Skip to content
Myr

bash_completion

This file

Path

bash_completion

92 lines · 1.8 KiB

Last changed by

Add bash_completion for `nvm exec`Jordan Harbandbefore adoptione58d4ab

History of this file

Take it

1#!/usr/bin/env bash23# bash completion for Node Version Manager (NVM)45__nvm_generate_completion()6{7  declare current_word8  current_word="${COMP_WORDS[COMP_CWORD]}"9  COMPREPLY=($(compgen -W "$1" -- "$current_word"))10  return 011}1213__nvm_commands ()14{15  declare current_word16  declare command1718  current_word="${COMP_WORDS[COMP_CWORD]}"1920  COMMANDS='\21    help install uninstall use run exec \22    alias unalias reinstall-packages \23    current list ls list-remote ls-remote \24    clear-cache deactivate unload \25    version which'2627    if [ ${#COMP_WORDS[@]} == 4 ]; then2829      command="${COMP_WORDS[COMP_CWORD-2]}"30      case "${command}" in31      alias)  __nvm_installed_nodes ;;32      esac3334    else3536      case "${current_word}" in37      -*)     __nvm_options ;;38      *)      __nvm_generate_completion "$COMMANDS" ;;39      esac4041    fi42}4344__nvm_options ()45{46  OPTIONS=''47  __nvm_generate_completion "$OPTIONS"48}4950__nvm_installed_nodes ()51{52  __nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"53}5455__nvm_aliases ()56{57  declare aliases58  aliases=""59  if [ -d $NVM_DIR/alias ]; then60    aliases="`cd $NVM_DIR/alias && ls`"61  fi62  echo "${aliases}"63}6465__nvm_alias ()66{67  __nvm_generate_completion "$(__nvm_aliases)"68}6970__nvm ()71{72  declare previous_word73  previous_word="${COMP_WORDS[COMP_CWORD-1]}"7475  case "$previous_word" in76  use|run|exec|ls|list|uninstall) __nvm_installed_nodes ;;77  alias|unalias)  __nvm_alias ;;78  *)              __nvm_commands ;;79  esac8081  return 082}8384# complete is a bash builtin, but recent versions of ZSH come with a function85# called bashcompinit that will create a complete in ZSH. If the user is in86# ZSH, load and run bashcompinit before calling the complete function.87if [[ -n ${ZSH_VERSION-} ]]; then88	autoload -U +X bashcompinit && bashcompinit89fi9091complete -o default -o nospace -F __nvm nvm92