[Refactor] `bash_completion`: Improve coding style
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Peter Dave Hello · committed by Jordan Harband · parent 113d807 · Browse files · 1 file·+28 added−35 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+28 added−35 removed
- other:+28 added−35 removed
Provenance
- Commit
62ee7cf- Tree
b3f47d8- Author
Peter Dave Hello <hsu@peterdavehello.org>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
113d807
1 file changed+28 added−35 removed
modified:bash_completion+28 added-35 removed
1 unmodified line2 3 # bash completion for Node Version Manager (NVM)4 5 if ! command -v nvm &> /dev/null; then6- return6+ return7 fi8 9-__nvm_generate_completion()10-{9+__nvm_generate_completion() {10 declare current_word11 current_word="${COMP_WORDS[COMP_CWORD]}"12 # shellcheck disable=SC220714- COMPREPLY=($(compgen -W "$1" -- "$current_word"))13+ COMPREPLY=($(compgen -W "$1" -- "${current_word}"))14 return 015 }16 18-__nvm_commands ()19-{17+__nvm_commands() {18 declare current_word19 declare command20 21 current_word="${COMP_WORDS[COMP_CWORD]}"5 unmodified lines27 install-latest-npm28 cache deactivate unload29 version version-remote which'30 33- if [ ${#COMP_WORDS[@]} == 4 ]; then31+ if [ ${#COMP_WORDS[@]} == 4 ]; then32 35- command="${COMP_WORDS[COMP_CWORD-2]}"36- case "${command}" in37- alias) __nvm_installed_nodes ;;38- esac33+ command="${COMP_WORDS[COMP_CWORD - 2]}"34+ case "${command}" in35+ alias) __nvm_installed_nodes ;;36+ esac37 40- else38+ else39 42- case "${current_word}" in43- -*) __nvm_options ;;44- *) __nvm_generate_completion "$COMMANDS" ;;45- esac40+ case "${current_word}" in41+ -*) __nvm_options ;;42+ *) __nvm_generate_completion "${COMMANDS}" ;;43+ esac44 47- fi45+ fi46 }47 50-__nvm_options ()51-{48+__nvm_options() {49 OPTIONS=''53- __nvm_generate_completion "$OPTIONS"50+ __nvm_generate_completion "${OPTIONS}"51 }52 56-__nvm_installed_nodes ()57-{53+__nvm_installed_nodes() {54 __nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"55 }56 61-__nvm_aliases ()62-{57+__nvm_aliases() {58 declare aliases59 aliases=""65- if [ -d "$NVM_DIR/alias" ]; then66- aliases="$(cd "$NVM_DIR/alias" && command find "$PWD" -type f | command sed "s:$PWD/::")"60+ if [ -d "${NVM_DIR}/alias" ]; then61+ aliases="$(cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"62 fi63 echo "${aliases} node stable unstable iojs"64 }65 71-__nvm_alias ()72-{66+__nvm_alias() {67 __nvm_generate_completion "$(__nvm_aliases)"68 }69 76-__nvm ()77-{70+__nvm() {71 declare previous_word79- previous_word="${COMP_WORDS[COMP_CWORD-1]}"72+ previous_word="${COMP_WORDS[COMP_CWORD - 1]}"73 81- case "$previous_word" in82- use|run|exec|ls|list|uninstall) __nvm_installed_nodes ;;83- alias|unalias) __nvm_alias ;;84- *) __nvm_commands ;;74+ case "${previous_word}" in75+ use | run | exec | ls | list | uninstall) __nvm_installed_nodes ;;76+ alias | unalias) __nvm_alias ;;77+ *) __nvm_commands ;;78 esac79 80 return 081 }10 unmodified lines