_nvm (1996B)
1 #compdef nvm 2 # ------------------------------------------------------------------------------ 3 # Description 4 # ----------- 5 # 6 # Completion script for nvm (https://github.com/creationix/nvm). 7 # 8 # ------------------------------------------------------------------------------ 9 # Authors 10 # ------- 11 # 12 # * Changwoo Park (https://github.com/pismute) 13 # 14 # ------------------------------------------------------------------------------ 15 16 local curcontext="$curcontext" state line ret=1 17 18 local -a _1st_arguments 19 _1st_arguments=( 20 'help:Show this message' 21 'install:Download and install a <version>' 22 'uninstall:Uninstall a <version>' 23 'use:Modify PATH to use <version>' 24 'run:Run <version> with <args> as arguments' 25 'ls:List installed [versions]' 26 'ls-remote:List remote versions available for install' 27 'deactivate:Undo effects of NVM on current shell' 28 'alias:Set an alias named <name> pointing to <version>. Show all aliases beginning with [<pattern>].' 29 'unalias:Deletes the alias named <name>' 30 'copy-packages:Install global NPM packages contained in <version> to current version' 31 'clear-cache:Clear cache' 32 'version:Show current node version' 33 ) 34 35 _arguments -C \ 36 '1: :->cmds' \ 37 '*: :->args' && ret=0 38 39 __nvm_aliases(){ 40 local aliases 41 aliases="" 42 if [ -d $NVM_DIR/alias ]; then 43 aliases="`cd $NVM_DIR/alias && ls`" 44 fi 45 echo "${aliases}" 46 } 47 48 __nvm_versions(){ 49 echo "$(nvm_ls) $(__nvm_aliases)" 50 } 51 52 case $state in 53 cmds) 54 _describe -t commands 'nvm command' _1st_arguments && ret=0 55 ;; 56 57 args) 58 case $words[2] in 59 (use|run|ls|list|install|uninstall|copy-packages) 60 61 _values 'version' $(__nvm_versions) && ret=0 62 ;; 63 64 (alias|unalias) 65 66 _values 'aliases' $(__nvm_aliases) && ret=0 67 ;; 68 69 *) 70 (( ret )) && _message 'no more arguments' 71 ;; 72 73 esac 74 ;; 75 esac 76 77 return ret 78 79 # Local Variables: 80 # mode: Shell-Script 81 # sh-indentation: 2 82 # indent-tabs-mode: nil 83 # sh-basic-offset: 2 84 # End: 85 # vim: ft=zsh sw=2 ts=2 et