From c85881961b98d6816975ae13381561f4d10b8cdb Mon Sep 17 00:00:00 2001 From: Ilan Cosman Date: Sun, 3 May 2020 21:41:08 -0700 Subject: [PATCH] Convert to meta/sub commands --- functions/fish_prompt.fish | 2 +- functions/lean.fish | 12 ++++ install.fish | 4 +- .../functions/lean_configure.fish | 2 +- lean_theme/functions/lean_help.fish | 59 +++++++++++++++++++ .../functions}/lean_uninstall.fish | 2 +- .../prompt_modules/fake_prompt/1_initial.fish | 2 +- .../prompt_modules/fish_prompt/1_initial.fish | 2 +- 8 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 functions/lean.fish rename functions/lean_wizard.fish => lean_theme/functions/lean_configure.fish (99%) create mode 100644 lean_theme/functions/lean_help.fish rename {functions => lean_theme/functions}/lean_uninstall.fish (97%) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index c3e476d..c590b11 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1,4 +1,4 @@ -# Created by lean_wizard +# Created by lean configure function fish_prompt --description 'Write out the prompt' set -g last_pipestatus $pipestatus set -g last_status $status diff --git a/functions/lean.fish b/functions/lean.fish new file mode 100644 index 0000000..72968a9 --- /dev/null +++ b/functions/lean.fish @@ -0,0 +1,12 @@ +function lean -a subcommand + set -l leanSubCommand "lean_$subcommand" + set -l leanCommands 'configure' 'test' 'uninstall' 'help' + + if contains $subcommand $leanCommands + source "$__fish_config_dir/lean_theme/functions/$leanSubCommand.fish" + $leanSubCommand $argv[2..-1] + else + lean help + end + functions -e $leanSubCommand +end \ No newline at end of file diff --git a/install.fish b/install.fish index 308f24d..4b42e4c 100644 --- a/install.fish +++ b/install.fish @@ -78,9 +78,9 @@ function lean_install set_color $fish_color_normal if _user_confirm_defaultYes 'Configure lean prompt?' - lean_wizard + lean configure else - echo -e '\n''Run lean_wizard to configure your prompt.' + echo -e '\n''Run lean configure to configure your prompt.' end end diff --git a/functions/lean_wizard.fish b/lean_theme/functions/lean_configure.fish similarity index 99% rename from functions/lean_wizard.fish rename to lean_theme/functions/lean_configure.fish index ecaa30b..4f8d209 100644 --- a/functions/lean_wizard.fish +++ b/lean_theme/functions/lean_configure.fish @@ -1,4 +1,4 @@ -function lean_wizard +function lean_configure if test $COLUMNS -lt 55 || test $LINES -lt 21 echo 'Terminal size too small; must be at least 55 x 21' return 1 diff --git a/lean_theme/functions/lean_help.fish b/lean_theme/functions/lean_help.fish new file mode 100644 index 0000000..80a7a2e --- /dev/null +++ b/lean_theme/functions/lean_help.fish @@ -0,0 +1,59 @@ +function lean_help -a subcommand + set -g b (set_color -o) + set -g n (set_color normal) + set -g g (set_color $lean_color_green) + + set -g subcommandList \ + 'configure' \ + 'test' \ + 'uninstall' \ + 'help' + set -g descriptionList \ + 'run interactive configuration wizard' \ + 'perform diagnostics on lean theme' \ + 'uninstall lean theme' \ + 'print this help message' + + if contains $subcommand $subcommandList + if functions -q _help_$subcommand + _help_$subcommand + else + _generic_help_sub $subcommand + end + return 0 + end + + echo 'Usage: '$g'lean '$n$b'subcommand '$n'[options]' + echo + echo 'Subcommands:' + echo + for sub in $subcommandList + echo -n ' '$b$sub$n + printf '\r\033[14C' + _getDescription $sub + end + echo + echo 'Print help for a specific subcommand:' + echo + echo ' '$g'lean '$n'help '$b'subcommand'$n + + set -a rmVars b n g subcommandList descriptionList + for var in $rmVars + set -e $var + end +end + +function _getDescription -a subcommand + set -l descriptionIndex (contains -i $subcommand $subcommandList) + echo $descriptionList[$descriptionIndex] +end + +function _generic_help_sub -a subcommand + set -l description (_getDescription $subcommand) + set -l descriptionFirstLetter (string sub -l 1 $description) + set -l upperDescriptionFirstLetter (string upper $descriptionFirstLetter) + + echo 'Usage: '$g'lean '$n$b$subcommand$n + echo + string replace $descriptionFirstLetter $upperDescriptionFirstLetter $description +end \ No newline at end of file diff --git a/functions/lean_uninstall.fish b/lean_theme/functions/lean_uninstall.fish similarity index 97% rename from functions/lean_uninstall.fish rename to lean_theme/functions/lean_uninstall.fish index da3412a..1c5522d 100644 --- a/functions/lean_uninstall.fish +++ b/lean_theme/functions/lean_uninstall.fish @@ -1,5 +1,5 @@ function lean_uninstall - if _user_confirm_defaultNo 'Unininstall lean theme?' + if _user_confirm_defaultNo 'Uninstall lean theme?' set -l fishPrompt "$__fish_config_dir/functions/fish_prompt.fish" echo 'Uninstalling lean theme...' diff --git a/lean_theme/prompt_modules/fake_prompt/1_initial.fish b/lean_theme/prompt_modules/fake_prompt/1_initial.fish index 42686fa..048afe9 100644 --- a/lean_theme/prompt_modules/fake_prompt/1_initial.fish +++ b/lean_theme/prompt_modules/fake_prompt/1_initial.fish @@ -1,4 +1,4 @@ -# Created by lean_wizard +# Created by lean configure function fake_prompt --description 'Write out the prompt' set -g last_pipestatus $pipestatus set -g last_status $status \ No newline at end of file diff --git a/lean_theme/prompt_modules/fish_prompt/1_initial.fish b/lean_theme/prompt_modules/fish_prompt/1_initial.fish index ef281bd..198cbfb 100644 --- a/lean_theme/prompt_modules/fish_prompt/1_initial.fish +++ b/lean_theme/prompt_modules/fish_prompt/1_initial.fish @@ -1,4 +1,4 @@ -# Created by lean_wizard +# Created by lean configure function fish_prompt --description 'Write out the prompt' set -g last_pipestatus $pipestatus set -g last_status $status \ No newline at end of file