[Refactor] `bash_completion`: Improve coding style
parent
113d807e5a
commit
62ee7cf998
|
@ -3,20 +3,18 @@
|
|||
# bash completion for Node Version Manager (NVM)
|
||||
|
||||
if ! command -v nvm &> /dev/null; then
|
||||
return
|
||||
return
|
||||
fi
|
||||
|
||||
__nvm_generate_completion()
|
||||
{
|
||||
__nvm_generate_completion() {
|
||||
declare current_word
|
||||
current_word="${COMP_WORDS[COMP_CWORD]}"
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "$1" -- "$current_word"))
|
||||
COMPREPLY=($(compgen -W "$1" -- "${current_word}"))
|
||||
return 0
|
||||
}
|
||||
|
||||
__nvm_commands ()
|
||||
{
|
||||
__nvm_commands() {
|
||||
declare current_word
|
||||
declare command
|
||||
|
||||
|
@ -30,58 +28,53 @@ __nvm_commands ()
|
|||
cache deactivate unload
|
||||
version version-remote which'
|
||||
|
||||
if [ ${#COMP_WORDS[@]} == 4 ]; then
|
||||
if [ ${#COMP_WORDS[@]} == 4 ]; then
|
||||
|
||||
command="${COMP_WORDS[COMP_CWORD-2]}"
|
||||
case "${command}" in
|
||||
alias) __nvm_installed_nodes ;;
|
||||
esac
|
||||
command="${COMP_WORDS[COMP_CWORD - 2]}"
|
||||
case "${command}" in
|
||||
alias) __nvm_installed_nodes ;;
|
||||
esac
|
||||
|
||||
else
|
||||
else
|
||||
|
||||
case "${current_word}" in
|
||||
-*) __nvm_options ;;
|
||||
*) __nvm_generate_completion "$COMMANDS" ;;
|
||||
esac
|
||||
case "${current_word}" in
|
||||
-*) __nvm_options ;;
|
||||
*) __nvm_generate_completion "${COMMANDS}" ;;
|
||||
esac
|
||||
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
__nvm_options ()
|
||||
{
|
||||
__nvm_options() {
|
||||
OPTIONS=''
|
||||
__nvm_generate_completion "$OPTIONS"
|
||||
__nvm_generate_completion "${OPTIONS}"
|
||||
}
|
||||
|
||||
__nvm_installed_nodes ()
|
||||
{
|
||||
__nvm_installed_nodes() {
|
||||
__nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"
|
||||
}
|
||||
|
||||
__nvm_aliases ()
|
||||
{
|
||||
__nvm_aliases() {
|
||||
declare aliases
|
||||
aliases=""
|
||||
if [ -d "$NVM_DIR/alias" ]; then
|
||||
aliases="$(cd "$NVM_DIR/alias" && command find "$PWD" -type f | command sed "s:$PWD/::")"
|
||||
if [ -d "${NVM_DIR}/alias" ]; then
|
||||
aliases="$(cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"
|
||||
fi
|
||||
echo "${aliases} node stable unstable iojs"
|
||||
}
|
||||
|
||||
__nvm_alias ()
|
||||
{
|
||||
__nvm_alias() {
|
||||
__nvm_generate_completion "$(__nvm_aliases)"
|
||||
}
|
||||
|
||||
__nvm ()
|
||||
{
|
||||
__nvm() {
|
||||
declare previous_word
|
||||
previous_word="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
previous_word="${COMP_WORDS[COMP_CWORD - 1]}"
|
||||
|
||||
case "$previous_word" in
|
||||
use|run|exec|ls|list|uninstall) __nvm_installed_nodes ;;
|
||||
alias|unalias) __nvm_alias ;;
|
||||
*) __nvm_commands ;;
|
||||
case "${previous_word}" in
|
||||
use | run | exec | ls | list | uninstall) __nvm_installed_nodes ;;
|
||||
alias | unalias) __nvm_alias ;;
|
||||
*) __nvm_commands ;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
|
|
Loading…
Reference in New Issue