Skip to content
Myr

bash_completion

This file

Path

bash_completion

96 lines · 1.9 KiB

Last changed by

[Fix] bash_completion should make sure nvm loadedPeter Dave Hellobefore adoption952d006

History of this file

Take it

1#!/usr/bin/env bash23# bash completion for Node Version Manager (NVM)45if ! nvm &> /dev/null; then6    return7fi89__nvm_generate_completion()10{11  declare current_word12  current_word="${COMP_WORDS[COMP_CWORD]}"13  COMPREPLY=($(compgen -W "$1" -- "$current_word"))14  return 015}1617__nvm_commands ()18{19  declare current_word20  declare command2122  current_word="${COMP_WORDS[COMP_CWORD]}"2324  COMMANDS='25    help install uninstall use run exec26    alias unalias reinstall-packages27    current list ls list-remote ls-remote28    clear-cache deactivate unload29    version 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{50  OPTIONS=''51  __nvm_generate_completion "$OPTIONS"52}5354__nvm_installed_nodes ()55{56  __nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"57}5859__nvm_aliases ()60{61  declare aliases62  aliases=""63  if [ -d "$NVM_DIR/alias" ]; then64    aliases="$(cd "$NVM_DIR/alias" && command find "$PWD" -type f | command sed "s:$PWD/::")"65  fi66  echo "${aliases} node stable unstable iojs"67}6869__nvm_alias ()70{71  __nvm_generate_completion "$(__nvm_aliases)"72}7374__nvm ()75{76  declare previous_word77  previous_word="${COMP_WORDS[COMP_CWORD-1]}"7879  case "$previous_word" in80  use|run|exec|ls|list|uninstall) __nvm_installed_nodes ;;81  alias|unalias)  __nvm_alias ;;82  *)              __nvm_commands ;;83  esac8485  return 086}8788# complete is a bash builtin, but recent versions of ZSH come with a function89# called bashcompinit that will create a complete in ZSH. If the user is in90# ZSH, load and run bashcompinit before calling the complete function.91if [[ -n ${ZSH_VERSION-} ]]; then92  autoload -U +X bashcompinit && bashcompinit93fi9495complete -o default -o nospace -F __nvm nvm96