From 75441062c732bf6ba5141f72618a1b58edc62232 Mon Sep 17 00:00:00 2001 From: Ilan Cosman Date: Sat, 25 Apr 2020 14:52:39 -0700 Subject: [PATCH] Increase uninstall specificity, protect user files --- functions/fish_prompt.fish | 1 + functions/lean_uninstall.fish | 36 +++++++++++-------- functions/lean_wizard.fish | 16 ++++----- install.fish | 2 +- .../prompt_modules/fish_prompt/1_initial.fish | 1 + 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index fffab86..da83f3a 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1,3 +1,4 @@ +# Created by lean_wizard function fish_prompt --description 'Write out the prompt' set -l lastExitCode $status diff --git a/functions/lean_uninstall.fish b/functions/lean_uninstall.fish index b5a3ef1..5e40d5b 100644 --- a/functions/lean_uninstall.fish +++ b/functions/lean_uninstall.fish @@ -3,33 +3,41 @@ function lean_uninstall echo "Uninstalling lean theme..." # ------------------Remove Files------------------ - rm "$__fish_config_dir/functions/fish_prompt.fish" - rm "$__fish_config_dir/functions/lean"* rm -r "$__fish_config_dir/lean_theme" + set -l fishPromptFirstLine (head -n 1 "$__fish_config_dir/functions/fish_prompt.fish") + if test $fishPromptFirstLine = "# Created by lean_wizard" + rm "$__fish_config_dir/functions/fish_prompt.fish" + end + + set -l leanFunctions git_prompt load_right_prompt_modules pwd right_prompt uninstall wizard + for func in $leanFunctions + rm "$__fish_config_dir/functions/lean_$func.fish" + end + # --------------Erase Theme Variables-------------- # --------------Prompt-------------- - set -a vars lean_prompt_connection lean_prompt_connection_color + set -a rmVars lean_prompt_connection lean_prompt_connection_color # --------------Colors-------------- - set -a vars lean_color_{green, light_blue, dark_blue, gold} + set -a rmVars lean_color_{green, light_blue, dark_blue, gold} # ---------------Pwd--------------- - set -a vars fish_prompt_pwd_dir_length lean_shorten_pwd_margin + set -a rmVars fish_prompt_pwd_dir_length lean_shorten_pwd_margin # ------------Git prompt------------ - set -a vars __fish_git_prompt_{show_informative_status, showstashstate} + set -a rmVars __fish_git_prompt_{show_informative_status, showstashstate} # -------Symbols------- - set -a vars __fish_git_prompt_char_{stateseparator, cleanstate, upstream_ahead, upstream_behind} - set -a vars __fish_git_prompt_char_{stagedstate, dirtystate, untrackedfiles, stashstate} + set -a rmVars __fish_git_prompt_char_{stateseparator, cleanstate, upstream_ahead, upstream_behind} + set -a rmVars __fish_git_prompt_char_{stagedstate, dirtystate, untrackedfiles, stashstate} # --------Colors-------- - set -a vars __fish_git_prompt_color_{branch, upstream, stagedstate, dirtystate, untrackedfiles, stashstate} + set -a rmVars __fish_git_prompt_color_{branch, upstream, stagedstate, dirtystate, untrackedfiles, stashstate} # ----------------Right Prompt Modules---------------- - set -a vars lean_right_prompt_modules + set -a rmVars lean_right_prompt_modules # --------------Timer-------------- - set -a vars lean_timer_{color, decimals, duration} + set -a rmVars lean_timer_{color, decimals, duration} # ---------------SSH--------------- - set -a vars lean_ssh_color + set -a rmVars lean_ssh_color - for var in $vars + for var in $rmVars set -e $var end @@ -41,7 +49,7 @@ function lean_uninstall end end -function _user_confirm_defaultNo --argument-names question +function _user_confirm_defaultNo -a question while true read -P "$question [y/N] " input diff --git a/functions/lean_wizard.fish b/functions/lean_wizard.fish index 27c4dc6..cc03255 100644 --- a/functions/lean_wizard.fish +++ b/functions/lean_wizard.fish @@ -149,10 +149,10 @@ function _promptSpacing end end -function _assemblePrompt --argument-names which - set -g moduleDir "$__fish_config_dir/lean_theme/prompt_modules/$which""_prompt" +function _assemblePrompt -a whichPrompt + set -g moduleDir "$__fish_config_dir/lean_theme/prompt_modules/$whichPrompt""_prompt" - if test $which = "fish" + if test $whichPrompt = "fish" set -g promptDir "$__fish_config_dir/functions/fish_prompt.fish" else set -g promptDir "$__fish_config_dir/lean_theme/temp_prompt.fish" @@ -173,12 +173,12 @@ function _assemblePrompt --argument-names which end end -function _addMod --argument-names file +function _addMod -a file cat "$moduleDir/$file.fish" >>$promptDir printf "\n\n" >>$promptDir end -function _title --argument-names title +function _title -a title set -l midCols (math $columns/2) set -l midTitle (math (string length $title)/2) @@ -190,13 +190,13 @@ function _title --argument-names title set_color normal end -function _option --argument-names symbol text +function _option -a symbol text set_color -o echo "($symbol) $text" set_color normal end -function _displayPrompt --argument-names var_name var_value +function _displayPrompt -a var_name var_value set -g $var_name $var_value _assemblePrompt fake source $promptDir @@ -236,7 +236,7 @@ function _finish _quit end -function _menu --argument-names question options +function _menu -a question options set -l optionList (string split "/" $options) set -l bold (set_color -o) set -l norm (set_color normal) diff --git a/install.fish b/install.fish index fb52c55..f5d3cf6 100644 --- a/install.fish +++ b/install.fish @@ -71,7 +71,7 @@ function lean_install end end -function _user_confirm_defaultYes --argument-names question +function _user_confirm_defaultYes -a question while true read -P "$question [Y/n] " input diff --git a/lean_theme/prompt_modules/fish_prompt/1_initial.fish b/lean_theme/prompt_modules/fish_prompt/1_initial.fish index 8056ebd..6f4b960 100644 --- a/lean_theme/prompt_modules/fish_prompt/1_initial.fish +++ b/lean_theme/prompt_modules/fish_prompt/1_initial.fish @@ -1,2 +1,3 @@ +# Created by lean_wizard function fish_prompt --description 'Write out the prompt' set -l lastExitCode $status \ No newline at end of file