1
0
Fork 0

Add nvm to node module

pull/331/head
Changwoo Park 12 years ago committed by Changwoo Park
parent 13b501adaf
commit 8653019fe0

3
.gitmodules vendored

@ -7,3 +7,6 @@
[submodule "modules/completion/external"] [submodule "modules/completion/external"]
path = modules/completion/external path = modules/completion/external
url = https://github.com/zsh-users/zsh-completions.git url = https://github.com/zsh-users/zsh-completions.git
[submodule "modules/node/nvm"]
path = modules/node/nvm
url = https://github.com/creationix/nvm

@ -3,6 +3,8 @@ Node.js
Provides utility functions for [Node.js][1] and loads [npm][2] completion. Provides utility functions for [Node.js][1] and loads [npm][2] completion.
Also, provides [nvm][5]. nvm use default if you have default alias.
Functions Functions
--------- ---------
@ -15,9 +17,11 @@ Authors
*The authors of this module should be contacted via the [issue tracker][4].* *The authors of this module should be contacted via the [issue tracker][4].*
- [Sorin Ionescu](https://github.com/sorin-ionescu) - [Sorin Ionescu](https://github.com/sorin-ionescu)
- [Changwoo Park](https://github.com/pismute)
[1]: http://nodejs.org [1]: http://nodejs.org
[2]: http://npmjs.org [2]: http://npmjs.org
[3]: http://nodejs.org/api [3]: http://nodejs.org/api
[4]: https://github.com/sorin-ionescu/prezto/issues [4]: https://github.com/sorin-ionescu/prezto/issues
[5]: https://github.com/creationix/nvm

@ -0,0 +1,85 @@
#compdef nvm
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for nvm (https://github.com/creationix/nvm).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Changwoo Park (https://github.com/pismute)
#
# ------------------------------------------------------------------------------
local curcontext="$curcontext" state line ret=1
local -a _1st_arguments
_1st_arguments=(
'help:Show this message'
'install:Download and install a <version>'
'uninstall:Uninstall a <version>'
'use:Modify PATH to use <version>'
'run:Run <version> with <args> as arguments'
'ls:List installed [versions]'
'ls-remote:List remote versions available for install'
'deactivate:Undo effects of NVM on current shell'
'alias:Set an alias named <name> pointing to <version>. Show all aliases beginning with [<pattern>].'
'unalias:Deletes the alias named <name>'
'copy-packages:Install global NPM packages contained in <version> to current version'
'clear-cache:Clear cache'
'version:Show current node version'
)
_arguments -C \
'1: :->cmds' \
'*: :->args' && ret=0
__nvm_aliases(){
local aliases
aliases=""
if [ -d $NVM_DIR/alias ]; then
aliases="`cd $NVM_DIR/alias && ls`"
fi
echo "${aliases}"
}
__nvm_versions(){
echo "$(nvm_ls) $(__nvm_aliases)"
}
case $state in
cmds)
_describe -t commands 'nvm command' _1st_arguments && ret=0
;;
args)
case $words[2] in
(use|run|ls|list|install|uninstall|copy-packages)
_values 'version' $(__nvm_versions) && ret=0
;;
(alias|unalias)
_values 'aliases' $(__nvm_aliases) && ret=0
;;
*)
(( ret )) && _message 'no more arguments'
;;
esac
;;
esac
return ret
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et

@ -5,6 +5,19 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # Sorin Ionescu <sorin.ionescu@gmail.com>
# #
# make defualt NVM_DIR to ~/.nvm
if [[ $NVM_DIR = "" ]]; then
export NVM_DIR=~/.nvm
fi
# load nvm
source "${0:h}/nvm/nvm.sh"
# nvm use default if nvm has default
if [ "$(nvm alias default)" != "" ]; then
nvm use default
fi
# Return if requirements are not found. # Return if requirements are not found.
if (( ! $+commands[node] )); then if (( ! $+commands[node] )); then
return 1 return 1

@ -0,0 +1 @@
Subproject commit 59c8eda18c9137c5a06dbfd835658938d9601b8d
Loading…
Cancel
Save