2020-05-04 07:41:08 +03:00
|
|
|
function lean_configure
|
2020-04-20 19:38:41 +03:00
|
|
|
if test $COLUMNS -lt 55 || test $LINES -lt 21
|
2020-04-30 00:52:58 +03:00
|
|
|
echo 'Terminal size too small; must be at least 55 x 21'
|
2020-04-20 19:38:41 +03:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
set -g fishPrompt "$__fish_config_dir/functions/fish_prompt.fish"
|
2020-05-04 18:24:09 +03:00
|
|
|
set -g fakePrompt "$lean_dir/fake_prompt.fish"
|
2020-04-28 01:37:08 +03:00
|
|
|
|
2020-04-20 19:38:41 +03:00
|
|
|
set -g columns $COLUMNS
|
2020-04-28 01:37:08 +03:00
|
|
|
if test $columns -gt 100
|
|
|
|
set -g columns 100
|
|
|
|
end
|
2020-04-20 19:38:41 +03:00
|
|
|
set -g lines $LINES
|
|
|
|
|
|
|
|
_begin
|
|
|
|
end
|
|
|
|
|
|
|
|
function _begin
|
|
|
|
_setDefaults
|
2020-04-30 03:06:11 +03:00
|
|
|
_promptTime
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function _setDefaults
|
2020-04-26 03:27:06 +03:00
|
|
|
if test $lines -ge 26
|
2020-04-30 03:06:11 +03:00
|
|
|
set -g new_line true
|
2020-04-26 03:27:06 +03:00
|
|
|
else
|
2020-04-30 03:06:11 +03:00
|
|
|
set -g new_line false
|
2020-04-26 03:27:06 +03:00
|
|
|
end
|
2020-04-30 03:06:11 +03:00
|
|
|
set -g prompt_height 2
|
|
|
|
set -g fake_lean_time_format ''
|
2020-04-30 00:52:58 +03:00
|
|
|
set -g fake_lean_prompt_connection ' '
|
2020-04-21 06:35:56 +03:00
|
|
|
set -g fake_lean_prompt_connection_color 6C6C6C
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|
|
|
|
|
2020-04-30 03:06:11 +03:00
|
|
|
function _promptTime
|
|
|
|
_title 'Show current time?'
|
|
|
|
|
|
|
|
_option 1 'No'
|
|
|
|
_displayPrompt fake_lean_time_format ''
|
|
|
|
|
|
|
|
_option 2 '24-hour format'
|
|
|
|
_displayPrompt fake_lean_time_format '%T'
|
|
|
|
|
|
|
|
_option 3 '12-hour format'
|
|
|
|
_displayPrompt fake_lean_time_format '%r'
|
|
|
|
|
|
|
|
_displayRestartAndQuit
|
|
|
|
|
|
|
|
switch (_menu 'Choice' 1/2/3/r/q)
|
|
|
|
case 1
|
|
|
|
set -g fake_lean_time_format ''
|
|
|
|
_promptHeight
|
|
|
|
case 2
|
|
|
|
set -g fake_lean_time_format '%T'
|
|
|
|
_promptHeight
|
|
|
|
case 3
|
|
|
|
set -g fake_lean_time_format '%r'
|
|
|
|
_promptHeight
|
|
|
|
case r
|
|
|
|
_begin
|
|
|
|
case q
|
|
|
|
_quit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-20 19:38:41 +03:00
|
|
|
function _promptHeight
|
2020-04-30 00:52:58 +03:00
|
|
|
_title 'Prompt Height'
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 1 'One line'
|
2020-04-20 19:38:41 +03:00
|
|
|
_displayPrompt prompt_height 1
|
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 2 'Two lines'
|
2020-04-20 19:38:41 +03:00
|
|
|
_displayPrompt prompt_height 2
|
|
|
|
|
|
|
|
_displayRestartAndQuit
|
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
switch (_menu 'Choice' 1/2/r/q)
|
2020-04-20 19:38:41 +03:00
|
|
|
case 1
|
|
|
|
set -g prompt_height 1
|
2020-04-21 21:52:24 +03:00
|
|
|
_promptSpacing
|
2020-04-20 19:38:41 +03:00
|
|
|
case 2
|
|
|
|
set -g prompt_height 2
|
|
|
|
_promptConnection
|
|
|
|
case r
|
|
|
|
_begin
|
|
|
|
case q
|
|
|
|
_quit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function _promptConnection
|
2020-04-30 00:52:58 +03:00
|
|
|
_title 'Prompt Connection'
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 1 'Disconnected'
|
|
|
|
_displayPrompt fake_lean_prompt_connection ' '
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 2 'Dotted'
|
|
|
|
_displayPrompt fake_lean_prompt_connection '·'
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 3 'Solid'
|
|
|
|
_displayPrompt fake_lean_prompt_connection '─'
|
2020-04-20 19:38:41 +03:00
|
|
|
|
|
|
|
_displayRestartAndQuit
|
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
switch (_menu 'Choice' 1/2/3/r/q)
|
2020-04-20 19:38:41 +03:00
|
|
|
case 1
|
2020-04-30 00:52:58 +03:00
|
|
|
set -g fake_lean_prompt_connection ' '
|
2020-04-20 21:12:57 +03:00
|
|
|
_promptSpacing
|
2020-04-20 19:38:41 +03:00
|
|
|
case 2
|
2020-04-30 00:52:58 +03:00
|
|
|
set -g fake_lean_prompt_connection '·'
|
2020-04-20 19:38:41 +03:00
|
|
|
_promptConnectionColor
|
|
|
|
case 3
|
2020-04-30 00:52:58 +03:00
|
|
|
set -g fake_lean_prompt_connection '─'
|
2020-04-20 19:38:41 +03:00
|
|
|
_promptConnectionColor
|
|
|
|
case r
|
|
|
|
_begin
|
|
|
|
case q
|
|
|
|
_quit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function _promptConnectionColor
|
2020-04-30 00:52:58 +03:00
|
|
|
_title 'Connection Color'
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 1 'Lightest'
|
2020-04-21 06:35:56 +03:00
|
|
|
_displayPrompt fake_lean_prompt_connection_color 808080
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 2 'Light'
|
2020-04-21 06:35:56 +03:00
|
|
|
_displayPrompt fake_lean_prompt_connection_color 6C6C6C
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 3 'Dark'
|
2020-04-21 06:35:56 +03:00
|
|
|
_displayPrompt fake_lean_prompt_connection_color 585858
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 4 'Darkest'
|
2020-04-21 06:35:56 +03:00
|
|
|
_displayPrompt fake_lean_prompt_connection_color 444444
|
2020-04-20 19:38:41 +03:00
|
|
|
|
|
|
|
_displayRestartAndQuit
|
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
switch (_menu 'Choice' 1/2/3/4/r/q)
|
2020-04-20 19:38:41 +03:00
|
|
|
case 1
|
2020-04-21 06:35:56 +03:00
|
|
|
set -g fake_lean_prompt_connection_color 808080
|
2020-04-20 19:38:41 +03:00
|
|
|
_promptSpacing
|
|
|
|
case 2
|
2020-04-21 06:35:56 +03:00
|
|
|
set -g fake_lean_prompt_connection_color 6C6C6C
|
2020-04-20 19:38:41 +03:00
|
|
|
_promptSpacing
|
|
|
|
case 3
|
2020-04-21 06:35:56 +03:00
|
|
|
set -g fake_lean_prompt_connection_color 585858
|
2020-04-20 19:38:41 +03:00
|
|
|
_promptSpacing
|
|
|
|
case 4
|
2020-04-21 06:35:56 +03:00
|
|
|
set -g fake_lean_prompt_connection_color 444444
|
2020-04-20 19:38:41 +03:00
|
|
|
_promptSpacing
|
|
|
|
case r
|
|
|
|
_begin
|
|
|
|
case q
|
|
|
|
_quit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function _promptSpacing
|
2020-04-30 00:52:58 +03:00
|
|
|
_title 'Prompt Spacing'
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 1 'Compact'
|
2020-04-30 03:06:11 +03:00
|
|
|
_displayPrompt new_line true
|
2020-04-30 00:52:58 +03:00
|
|
|
echo -ne '\r\033[1A'
|
2020-04-30 03:06:11 +03:00
|
|
|
_displayPrompt new_line false
|
2020-04-20 19:38:41 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option 2 'Sparse'
|
2020-04-30 03:06:11 +03:00
|
|
|
_displayPrompt new_line true
|
2020-04-30 00:52:58 +03:00
|
|
|
echo -ne '\r\033[1A'
|
2020-04-30 03:06:11 +03:00
|
|
|
_displayPrompt new_line true
|
2020-04-20 19:38:41 +03:00
|
|
|
|
|
|
|
_displayRestartAndQuit
|
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
switch (_menu 'Choice' 1/2/r/q)
|
2020-04-20 19:38:41 +03:00
|
|
|
case 1
|
2020-04-30 03:06:11 +03:00
|
|
|
set -g new_line false
|
2020-04-20 19:38:41 +03:00
|
|
|
_finish
|
|
|
|
case 2
|
2020-04-30 03:06:11 +03:00
|
|
|
set -g new_line true
|
2020-04-20 19:38:41 +03:00
|
|
|
_finish
|
|
|
|
case r
|
|
|
|
_begin
|
|
|
|
case q
|
|
|
|
_quit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-26 00:52:39 +03:00
|
|
|
function _assemblePrompt -a whichPrompt
|
2020-05-04 18:24:09 +03:00
|
|
|
set -g moduleDir "$lean_dir/prompt_modules/$whichPrompt""_prompt"
|
2020-04-21 06:35:56 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
if test "$whichPrompt" = 'fish'
|
2020-04-28 01:10:59 +03:00
|
|
|
set -g promptDir $fishPrompt
|
2020-04-21 06:35:56 +03:00
|
|
|
else
|
2020-04-28 01:10:59 +03:00
|
|
|
set -g promptDir $fakePrompt
|
2020-04-21 06:35:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
echo -n >$promptDir
|
2020-04-20 19:38:41 +03:00
|
|
|
|
|
|
|
_addMod 1_initial
|
2020-04-30 03:06:11 +03:00
|
|
|
if test "$new_line" = 'true'
|
2020-04-20 19:38:41 +03:00
|
|
|
_addMod 2_newline
|
|
|
|
end
|
2020-04-30 00:52:58 +03:00
|
|
|
_addMod '3_'$prompt_height'Line'
|
2020-04-20 19:38:41 +03:00
|
|
|
_addMod 4_final
|
2020-04-21 21:52:24 +03:00
|
|
|
if test $prompt_height -eq 1
|
|
|
|
_addMod 5_rightPrompt
|
|
|
|
end
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|
|
|
|
|
2020-04-26 00:52:39 +03:00
|
|
|
function _addMod -a file
|
2020-04-21 21:52:24 +03:00
|
|
|
cat "$moduleDir/$file.fish" >>$promptDir
|
2020-04-30 00:52:58 +03:00
|
|
|
printf '\n\n' >>$promptDir
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|
|
|
|
|
2020-04-26 00:52:39 +03:00
|
|
|
function _title -a title
|
2020-04-28 02:12:12 +03:00
|
|
|
clear
|
2020-04-20 19:38:41 +03:00
|
|
|
set -l midCols (math $columns/2)
|
|
|
|
set -l midTitle (math (string length $title)/2)
|
|
|
|
|
|
|
|
for i in (seq (math $midCols-$midTitle))
|
2020-04-30 00:52:58 +03:00
|
|
|
echo -n ' '
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|
2020-04-21 21:52:24 +03:00
|
|
|
set_color -o
|
2020-04-20 19:38:41 +03:00
|
|
|
echo $title
|
2020-04-21 21:52:24 +03:00
|
|
|
set_color normal
|
|
|
|
end
|
|
|
|
|
2020-04-26 00:52:39 +03:00
|
|
|
function _option -a symbol text
|
2020-04-21 21:52:24 +03:00
|
|
|
set_color -o
|
2020-04-23 01:19:58 +03:00
|
|
|
echo "($symbol) $text"
|
2020-04-21 21:52:24 +03:00
|
|
|
set_color normal
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|
|
|
|
|
2020-04-26 00:52:39 +03:00
|
|
|
function _displayPrompt -a var_name var_value
|
2020-04-20 19:38:41 +03:00
|
|
|
set -g $var_name $var_value
|
2020-04-26 03:27:06 +03:00
|
|
|
|
2020-04-21 06:35:56 +03:00
|
|
|
_assemblePrompt fake
|
|
|
|
source $promptDir
|
|
|
|
fake_prompt
|
2020-04-26 03:27:06 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
printf '\n\n'
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function _displayRestartAndQuit
|
2020-04-30 00:52:58 +03:00
|
|
|
echo -e '(r) Restart from the beginning\n'
|
|
|
|
echo -e '(q) Quit and do nothing\n'
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|
|
|
|
|
2020-05-09 08:48:35 +03:00
|
|
|
function _quit --on-signal INT
|
2020-04-22 03:40:49 +03:00
|
|
|
functions -e fish_right_prompt
|
2020-04-20 19:38:41 +03:00
|
|
|
source $fishPrompt
|
|
|
|
clear
|
|
|
|
end
|
|
|
|
|
|
|
|
function _finish
|
2020-04-30 00:52:58 +03:00
|
|
|
_title 'Overwrite fish_prompt?'
|
2020-04-23 01:19:58 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option y 'Yes'
|
|
|
|
printf '\n\n'
|
2020-04-23 01:19:58 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
_option n 'No'
|
|
|
|
printf '\n\n'
|
2020-04-23 01:19:58 +03:00
|
|
|
|
2020-04-30 00:52:58 +03:00
|
|
|
switch (_menu 'Choice' y/n)
|
2020-04-23 01:19:58 +03:00
|
|
|
case y
|
|
|
|
_assemblePrompt fish
|
2020-04-29 07:19:32 +03:00
|
|
|
set -U lean_prompt_connection_icon $fake_lean_prompt_connection
|
2020-04-23 01:19:58 +03:00
|
|
|
set -U lean_prompt_connection_color $fake_lean_prompt_connection_color
|
2020-04-30 03:06:11 +03:00
|
|
|
if test $fake_lean_time_format = ''
|
2020-04-30 05:19:17 +03:00
|
|
|
if contains 'time' $lean_right_prompt_items
|
|
|
|
set -e lean_right_prompt_items[(contains -i 'time' $lean_right_prompt_items)]
|
|
|
|
end
|
2020-04-30 03:06:11 +03:00
|
|
|
set -e lean_time_format
|
|
|
|
else
|
|
|
|
set -a lean_right_prompt_items 'time'
|
|
|
|
set -U lean_time_format $fake_lean_time_format
|
|
|
|
end
|
2020-04-23 01:19:58 +03:00
|
|
|
case n
|
|
|
|
end
|
|
|
|
|
2020-04-21 06:35:56 +03:00
|
|
|
_quit
|
2020-04-22 06:06:05 +03:00
|
|
|
end
|
|
|
|
|
2020-04-26 00:52:39 +03:00
|
|
|
function _menu -a question options
|
2020-04-30 00:52:58 +03:00
|
|
|
set -l optionList (string split '/' $options)
|
2020-04-22 06:25:40 +03:00
|
|
|
set -l bold (set_color -o)
|
|
|
|
set -l norm (set_color normal)
|
2020-04-23 01:19:58 +03:00
|
|
|
|
2020-04-22 06:06:05 +03:00
|
|
|
while true
|
2020-04-22 06:25:40 +03:00
|
|
|
read -P $bold"$question [$options] "$norm input
|
2020-04-22 06:06:05 +03:00
|
|
|
|
|
|
|
if contains $input $optionList
|
|
|
|
echo $input
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2020-04-20 19:38:41 +03:00
|
|
|
end
|