formatted apm completion and used helper function

pull/1782/head
Gurkirat Singh 2021-01-10 19:18:41 +05:30
parent 2c39053879
commit f71d76990a
No known key found for this signature in database
GPG Key ID: CFD64E1DCB3DA835
1 changed files with 55 additions and 50 deletions

View File

@ -24,54 +24,59 @@
# repo: https://github.com/vigo/apm-bash-completion # repo: https://github.com/vigo/apm-bash-completion
__apm(){ if _command_exists apm
local cur prev options apm_command then
COMPREPLY=() function __apm(){
cur="${COMP_WORDS[COMP_CWORD]}" local cur prev options apm_command
prev="${COMP_WORDS[COMP_CWORD-1]}" COMPREPLY=()
__apm_get_command cur="${COMP_WORDS[COMP_CWORD]}"
if [[ $cur = -* ]]; then prev="${COMP_WORDS[COMP_CWORD-1]}"
options="--color" __apm_get_command
if [[ -z $apm_command ]]; then if [[ $cur = -* ]]; then
options="$options --version --help" options="--color"
if [[ -z $apm_command ]]; then
options="$options --version --help"
fi
if [[ $apm_command && $apm_command = publish ]]; then
options="--tag --rename"
fi
else
if [[ -z $apm_command || $apm_command = help ]]; then
options="help clean config dedupe deinstall delete dev develop docs erase featured home init install link linked links list ln lns login ls open outdated publish rebuild rebuild-module-cache remove rm search show star starred stars test uninstall unlink unpublish unstar update upgrade view"
fi
if [[ $apm_command && $apm_command = publish ]]; then
options="major minor patch build"
fi
if [[ $apm_command && $apm_command = config ]]; then
options="set get delete list edit"
fi
fi fi
if [[ $apm_command && $apm_command = publish ]]; then COMPREPLY=($(compgen -W "$options" -- "$cur"))
options="--tag --rename" }
fi
else function __apm_get_command() {
if [[ -z $apm_command || $apm_command = help ]]; then local i
options="help clean config dedupe deinstall delete dev develop docs erase featured home init install link linked links list ln lns login ls open outdated publish rebuild rebuild-module-cache remove rm search show star starred stars test uninstall unlink unpublish unstar update upgrade view" for ((i=1; i < $COMP_CWORD; ++i)); do
fi local arg=${COMP_WORDS[$i]}
if [[ $apm_command && $apm_command = publish ]]; then case $arg in
options="major minor patch build" [^-]*)
fi apm_command=$arg
if [[ $apm_command && $apm_command = config ]]; then return;;
options="set get delete list edit" --version)
fi apm_command=-
fi return;;
COMPREPLY=($(compgen -W "$options" -- "$cur")) --help)
} apm_command=help
__apm_get_command() { return;;
local i publish)
for ((i=1; i < $COMP_CWORD; ++i)); do apm_command=publish
local arg=${COMP_WORDS[$i]} return;;
case $arg in config)
[^-]*) apm_command=config
apm_command=$arg return;;
return;; esac
--version) done
apm_command=- }
return;;
--help) complete -F __apm -o bashdefault -o default apm
apm_command=help fi
return;;
publish)
apm_command=publish
return;;
config)
apm_command=config
return;;
esac
done
}
complete -F __apm -o bashdefault -o default apm