From 165c8c697787769cbf2c6b67b736074683bdca31 Mon Sep 17 00:00:00 2001 From: Ilan Cosman Date: Mon, 20 Apr 2020 09:38:41 -0700 Subject: [PATCH] Alot of work on wizard, add prompt_modules --- functions/fish_prompt.fish | 23 ++- functions/lean_pwd.fish | 10 +- functions/lean_uninstall.fish | 4 +- functions/lean_user_ask.fish | 9 +- functions/lean_wizard.fish | 212 ++++++++++++++++++++++++++++ install.fish | 26 ++-- lean_theme/prompt_modules/1_initial | 2 + lean_theme/prompt_modules/2_newline | 1 + lean_theme/prompt_modules/3_1Line | 1 + lean_theme/prompt_modules/3_2Line | 17 +++ lean_theme/prompt_modules/4_final | 9 ++ lean_theme/temp_prompt.fish | 29 ++++ 12 files changed, 318 insertions(+), 25 deletions(-) create mode 100644 functions/lean_wizard.fish create mode 100644 lean_theme/prompt_modules/1_initial create mode 100644 lean_theme/prompt_modules/2_newline create mode 100644 lean_theme/prompt_modules/3_1Line create mode 100644 lean_theme/prompt_modules/3_2Line create mode 100644 lean_theme/prompt_modules/4_final create mode 100644 lean_theme/temp_prompt.fish diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index c7d7fc6..6269de9 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1,9 +1,22 @@ function fish_prompt --description 'Write out the prompt' set -l last_status $status - echo - - echo (lean_pwd)(lean_git_prompt) - + if test (math $CMD_DURATION/1000) -gt $lean_timer_duration + for i in (seq (math $COLUMNS-(string length (echo -n " "(math --scale=$lean_timer_decimals $CMD_DURATION/1000)"s"))-1)) + set_color $lean_prompt_connection_color + echo -n $lean_prompt_connection + set_color $fish_color_normal + end + set_color $lean_timer_color + echo -n " "(math --scale=$lean_timer_decimals $CMD_DURATION/1000)"s" + set_color $fish_color_normal + else + for i in (seq (math $COLUMNS-1)) + set_color $lean_prompt_connection_color + echo -n $lean_prompt_connection + set_color $fish_color_normal + end + end + echo -e "\r"(lean_pwd)(lean_git_prompt)" " # Prompt character if test $last_status -eq 0 set_color $lean_green @@ -12,4 +25,4 @@ function fish_prompt --description 'Write out the prompt' end echo -n "❯ " set_color $fish_color_normal -end +end \ No newline at end of file diff --git a/functions/lean_pwd.fish b/functions/lean_pwd.fish index 7cebbce..14c3b4f 100644 --- a/functions/lean_pwd.fish +++ b/functions/lean_pwd.fish @@ -3,29 +3,29 @@ function lean_pwd set -l pwdSplitLength (count $pwdSplit) if test $pwdSplit[1] != "~" - set_color -o $lean_light_blue + set_color -o $lean_color_light_blue echo -n "/" set_color $fish_color_normal else - set_color -o $lean_light_blue + set_color -o $lean_color_light_blue echo -n $pwdSplit[1] set_color $fish_color_normal if test $pwdSplitLength -gt 1 - set_color $lean_dark_blue + set_color $lean_color_dark_blue echo -n "/" set_color $fish_color_normal end end - set_color $lean_dark_blue + set_color $lean_color_dark_blue echo -n (string join "/" $pwdSplit[2..-2]) if test $pwdSplitLength -gt 2 echo -n "/" end set_color $fish_color_normal - set_color -o $lean_light_blue + set_color -o $lean_color_light_blue if test $pwdSplitLength -gt 1 echo -n $pwdSplit[-1] end diff --git a/functions/lean_uninstall.fish b/functions/lean_uninstall.fish index 69dc55a..692eb3f 100644 --- a/functions/lean_uninstall.fish +++ b/functions/lean_uninstall.fish @@ -8,7 +8,9 @@ function lean_uninstall # ---------------Erase Theme Variables--------------- # --------------Colors-------------- - set -l vars $vars lean_green lean_light_blue lean_dark_blue lean_gold + set -l vars $vars lean_color_green lean_color_light_blue lean_color_dark_blue lean_color_gold + # --------------Timer-------------- + set -l vars $vars lean_timer_color lean_timer_decimals lean_timer_duration # ---------------Pwd--------------- set -l vars $vars fish_prompt_pwd_dir_length lean_shorten_pwd_margin # ------------Git prompt------------ diff --git a/functions/lean_user_ask.fish b/functions/lean_user_ask.fish index 65aca21..6beea42 100644 --- a/functions/lean_user_ask.fish +++ b/functions/lean_user_ask.fish @@ -2,7 +2,7 @@ function lean_user_ask --argument-names question options set -l optionList (string split "/" $options) for option in $optionList - set -l upperOption (string upper $option) + set -g upperOption (string upper $option) if contains $upperOption $optionList set -g default (_indexMinusOne $upperOption $optionList) @@ -13,16 +13,19 @@ function lean_user_ask --argument-names question options read -P "$question [$options] " input set -l splitInput (string split -m1 '' $input) - set -l lowerInput (string join0 (string lower $splitInput[1]) $splitInput[2]) - set -l upperInput (string join0 (string upper $splitInput[1]) $splitInput[2]) + set -l lowerInput (string join '' (string lower $splitInput[1]) $splitInput[2]) + set -l upperInput (string join '' (string upper $splitInput[1]) $splitInput[2]) if contains $lowerInput $optionList + echo $lowerInput return (_indexMinusOne $lowerInput $optionList) end if contains $upperInput $optionList + echo $upperInput return (_indexMinusOne $upperInput $optionList) end if test -z $input && set -q default + echo $upperOption return $default end end diff --git a/functions/lean_wizard.fish b/functions/lean_wizard.fish new file mode 100644 index 0000000..54f8196 --- /dev/null +++ b/functions/lean_wizard.fish @@ -0,0 +1,212 @@ +function lean_wizard + if test $COLUMNS -lt 55 || test $LINES -lt 21 + echo "Terminal size too small; must be at least 55 x 21" + return 1 + end + + set -g leanTimerDurationSave $lean_timer_duration + set -U lean_timer_duration 0 + set -g tempPrompt "$__fish_config_dir/lean_theme/temp_prompt.fish" + set -g moduleDir "$__fish_config_dir/lean_theme/prompt_modules" + set -g fishPrompt "$__fish_config_dir/functions/fish_prompt.fish" + set -g columns $COLUMNS + set -g lines $LINES + + _begin +end + +function _begin + clear + _setDefaults + _promptHeight +end + +function _setDefaults + set -g newline true + set -g lean_prompt_connection " " + set -g lean_prompt_connection_color 6C6C6C +end + +function _promptHeight + _title "Prompt Height" + + echo "(1) One line" + _displayPrompt prompt_height 1 + + echo "(2) Two lines" + _displayPrompt prompt_height 2 + + _displayRestartAndQuit + + switch (lean_user_ask "Choice" 1/2/r/q) + case 1 + set -g prompt_height 1 + _finish + case 2 + set -g prompt_height 2 + _promptConnection + case r + _begin + case q + _quit + end +end + +function _promptConnection + clear + _title "Prompt Connection" + + echo "(1) Disconnected" + _displayPrompt lean_prompt_connection " " + + echo "(2) Dotted" + _displayPrompt lean_prompt_connection "·" + + echo "(3) Solid" + _displayPrompt lean_prompt_connection "─" + + _displayRestartAndQuit + + switch (lean_user_ask "Choice" 1/2/3/r/q) + case 1 + set -U lean_prompt_connection " " + set -g lean_prompt_connection " " + _promptConnectionColor + case 2 + set -U lean_prompt_connection "·" + set -g lean_prompt_connection "·" + _promptConnectionColor + case 3 + set -U lean_prompt_connection "─" + set -g lean_prompt_connection "─" + _promptConnectionColor + case r + _begin + case q + _quit + end +end + +function _promptConnectionColor + clear + _title "Connection Color" + + echo "(1) Lightest" + _displayPrompt lean_prompt_connection_color 808080 + + echo "(2) Light" + _displayPrompt lean_prompt_connection_color 6C6C6C + + echo "(3) Dark" + _displayPrompt lean_prompt_connection_color 585858 + + echo "(4) Darkest" + _displayPrompt lean_prompt_connection_color 444444 + + _displayRestartAndQuit + + switch (lean_user_ask "Choice" 1/2/3/4/r/q) + case 1 + set -U lean_prompt_connection_color 808080 + set -g lean_prompt_connection_color 808080 + _promptSpacing + case 2 + set -U lean_prompt_connection_color 6C6C6C + set -g lean_prompt_connection_color 6C6C6C + _promptSpacing + case 3 + set -U lean_prompt_connection_color 585858 + set -g lean_prompt_connection_color 585858 + _promptSpacing + case 4 + set -U lean_prompt_connection_color 444444 + set -g lean_prompt_connection_color 444444 + _promptSpacing + case r + _begin + case q + _quit + end +end + +function _promptSpacing + clear + _title "Prompt Spacing" + + echo "(1) Compact" + _displayPrompt newline false + _displayPrompt newline false + + echo "(2) Sparse" + _displayPrompt newline true + _displayPrompt newline true + + _displayRestartAndQuit + + switch (lean_user_ask "Choice" 1/2/r/q) + case 1 + set -g newline false + _finish + case 2 + set -g newline true + _finish + case r + _begin + case q + _quit + end +end + +function _assemble_prompt + echo -n >$tempPrompt + + _addMod 1_initial + if test $newline = "true" + _addMod 2_newline + end + _addMod "3_"$prompt_height"Line" + _addMod 4_final +end + +function _addMod --argument-names file + cat "$moduleDir/$file" >>$tempPrompt +end + +function _title --argument-names title + set -l midCols (math $columns/2) + set -l midTitle (math (string length $title)/2) + + for i in (seq (math $midCols-$midTitle)) + echo -n " " + end + echo $title +end + +function _displayPrompt --argument-names var_name var_value + set -g $var_name $var_value + _assemble_prompt + source $tempPrompt + fish_prompt + echo + echo +end + +function _displayRestartAndQuit + echo -e "(r) Restart from the beginning\n" + echo -e "(q) Quit and do nothing\n" +end + +function _quit + set -U lean_timer_duration $leanTimerDurationSave + source $fishPrompt + fish_prompt + clear +end + +function _finish + set -U lean_timer_duration $leanTimerDurationSave + _assemble_prompt + cat $tempPrompt >$fishPrompt + source $fishPrompt + clear +end \ No newline at end of file diff --git a/install.fish b/install.fish index 497b5c4..9bbac7f 100644 --- a/install.fish +++ b/install.fish @@ -20,10 +20,14 @@ rm -rf $tempDir # ----------------Set Theme Variables---------------- # --------------Colors-------------- -set -U lean_green 5FD700 -set -U lean_light_blue 00AFFF -set -U lean_dark_blue 0087AF -set -U lean_gold D7AF00 +set -U lean_color_green 5FD700 +set -U lean_color_light_blue 00AFFF +set -U lean_color_dark_blue 0087AF +set -U lean_color_gold D7AF00 +# --------------Timer-------------- +set -U lean_timer_color 87875F +set -U lean_timer_decimals 0 +set -U lean_timer_duration 3 # ---------------Pwd--------------- set -U fish_prompt_pwd_dir_length 0 set -U lean_shorten_pwd_margin 5 @@ -40,13 +44,13 @@ set -U __fish_git_prompt_char_dirtystate ' !' set -U __fish_git_prompt_char_untrackedfiles ' ?' set -U __fish_git_prompt_char_stashstate " *" # --------Colors-------- -set -U __fish_git_prompt_color_branch $lean_green -set -U __fish_git_prompt_color_upstream $lean_green -set -U __fish_git_prompt_color_stagedstate $lean_gold -set -U __fish_git_prompt_color_dirtystate $lean_gold -set -U __fish_git_prompt_color_untrackedfiles $lean_light_blue -set -U __fish_git_prompt_color_stashstate $lean_green +set -U __fish_git_prompt_color_branch $lean_color_green +set -U __fish_git_prompt_color_upstream $lean_color_green +set -U __fish_git_prompt_color_stagedstate $lean_color_gold +set -U __fish_git_prompt_color_dirtystate $lean_color_gold +set -U __fish_git_prompt_color_untrackedfiles $lean_color_light_blue +set -U __fish_git_prompt_color_stashstate $lean_color_green -set_color $lean_green +set_color $lean_color_green echo "Lean theme installed! Restart fish to see your new prompt." set_color $fish_color_normal \ No newline at end of file diff --git a/lean_theme/prompt_modules/1_initial b/lean_theme/prompt_modules/1_initial new file mode 100644 index 0000000..3d6ef42 --- /dev/null +++ b/lean_theme/prompt_modules/1_initial @@ -0,0 +1,2 @@ +function fish_prompt --description 'Write out the prompt' + set -l last_status $status diff --git a/lean_theme/prompt_modules/2_newline b/lean_theme/prompt_modules/2_newline new file mode 100644 index 0000000..c6192e0 --- /dev/null +++ b/lean_theme/prompt_modules/2_newline @@ -0,0 +1 @@ + echo diff --git a/lean_theme/prompt_modules/3_1Line b/lean_theme/prompt_modules/3_1Line new file mode 100644 index 0000000..c12525d --- /dev/null +++ b/lean_theme/prompt_modules/3_1Line @@ -0,0 +1 @@ + echo -n (lean_pwd)(lean_git_prompt)" " diff --git a/lean_theme/prompt_modules/3_2Line b/lean_theme/prompt_modules/3_2Line new file mode 100644 index 0000000..0106bf5 --- /dev/null +++ b/lean_theme/prompt_modules/3_2Line @@ -0,0 +1,17 @@ + if test (math $CMD_DURATION/1000) -gt $lean_timer_duration + for i in (seq (math $COLUMNS-(string length (echo -n " "(math --scale=$lean_timer_decimals $CMD_DURATION/1000)"s"))-1)) + set_color $lean_prompt_connection_color + echo -n $lean_prompt_connection + set_color $fish_color_normal + end + set_color $lean_timer_color + echo -n " "(math --scale=$lean_timer_decimals $CMD_DURATION/1000)"s" + set_color $fish_color_normal + else + for i in (seq (math $COLUMNS-1)) + set_color $lean_prompt_connection_color + echo -n $lean_prompt_connection + set_color $fish_color_normal + end + end + echo -e "\r"(lean_pwd)(lean_git_prompt)" " diff --git a/lean_theme/prompt_modules/4_final b/lean_theme/prompt_modules/4_final new file mode 100644 index 0000000..727330b --- /dev/null +++ b/lean_theme/prompt_modules/4_final @@ -0,0 +1,9 @@ + # Prompt character + if test $last_status -eq 0 + set_color $lean_green + else + set_color $fish_color_error + end + echo -n "❯ " + set_color $fish_color_normal +end \ No newline at end of file diff --git a/lean_theme/temp_prompt.fish b/lean_theme/temp_prompt.fish new file mode 100644 index 0000000..b5b9701 --- /dev/null +++ b/lean_theme/temp_prompt.fish @@ -0,0 +1,29 @@ +function fish_prompt --description 'Write out the prompt' + set -l last_status $status + echo + if test (math $CMD_DURATION/1000) -gt $lean_timer_duration + for i in (seq (math $COLUMNS-(string length (echo -n " "(math --scale=$lean_timer_decimals $CMD_DURATION/1000)"s"))-1)) + set_color $lean_prompt_connection_color + echo -n $lean_prompt_connection + set_color $fish_color_normal + end + set_color $lean_timer_color + echo -n " "(math --scale=$lean_timer_decimals $CMD_DURATION/1000)"s" + set_color $fish_color_normal + else + for i in (seq (math $COLUMNS-1)) + set_color $lean_prompt_connection_color + echo -n $lean_prompt_connection + set_color $fish_color_normal + end + end + echo -e "\r"(lean_pwd)(lean_git_prompt)" " + # Prompt character + if test $last_status -eq 0 + set_color $lean_green + else + set_color $fish_color_error + end + echo -n "❯ " + set_color $fish_color_normal +end \ No newline at end of file