Convert to meta/sub commands

This commit is contained in:
Ilan Cosman 2020-05-03 21:41:08 -07:00
parent 5f5a18b91d
commit c85881961b
8 changed files with 78 additions and 7 deletions

View File

@ -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

12
functions/lean.fish Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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...'

View File

@ -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

View File

@ -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