1#!/usr/bin/env bash23# bash completion for Node Version Manager (NVM)45if ! command -v nvm &> /dev/null; then6 return7fi89__nvm_generate_completion() {10 declare current_word11 current_word="${COMP_WORDS[COMP_CWORD]}"12 # shellcheck disable=SC220713 COMPREPLY=($(compgen -W "$1" -- "${current_word}"))14 return 015}1617__nvm_commands() {18 declare current_word19 declare command2021 current_word="${COMP_WORDS[COMP_CWORD]}"2223 COMMANDS='24 help install uninstall use run exec25 alias unalias reinstall-packages26 current list ls list-remote ls-remote27 install-latest-npm28 cache deactivate unload29 version version-remote which'3031 if [ ${#COMP_WORDS[@]} == 4 ]; then3233 command="${COMP_WORDS[COMP_CWORD - 2]}"34 case "${command}" in35 alias) __nvm_installed_nodes ;;36 esac3738 else3940 case "${current_word}" in41 -*) __nvm_options ;;42 *) __nvm_generate_completion "${COMMANDS}" ;;43 esac4445 fi46}4748__nvm_options() {49 OPTIONS=''50 __nvm_generate_completion "${OPTIONS}"51}5253__nvm_installed_nodes() {54 __nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"55}5657__nvm_aliases() {58 declare aliases59 aliases=""60 if [ -d "${NVM_DIR}/alias" ]; then61 aliases="$(command cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"62 fi63 echo "${aliases} node stable unstable iojs"64}6566__nvm_alias() {67 __nvm_generate_completion "$(__nvm_aliases)"68}6970__nvm() {71 declare previous_word72 previous_word="${COMP_WORDS[COMP_CWORD - 1]}"7374 case "${previous_word}" in75 use | run | exec | ls | list | uninstall) __nvm_installed_nodes ;;76 alias | unalias) __nvm_alias ;;77 *) __nvm_commands ;;78 esac7980 return 081}8283# complete is a bash builtin, but recent versions of ZSH come with a function84# called bashcompinit that will create a complete in ZSH. If the user is in85# ZSH, load and run bashcompinit before calling the complete function.86if [[ -n ${ZSH_VERSION-} ]]; then87 # First calling compinit (only if not called yet!)88 # and then bashcompinit as mentioned by zsh man page.89 if ! command -v compinit > /dev/null; then90 autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then91 compinit -u92 else93 compinit94 fi95 fi96 autoload -U +X bashcompinit && bashcompinit97fi9899complete -o default -F __nvm nvm