From 8653019fe0a97d0a1d220774d50f6d2ea8d0eaa5 Mon Sep 17 00:00:00 2001 From: Changwoo Park Date: Tue, 27 Nov 2012 13:34:55 +0900 Subject: [PATCH] Add nvm to node module --- .gitmodules | 3 ++ modules/node/README.md | 4 ++ modules/node/functions/_nvm | 85 +++++++++++++++++++++++++++++++++++++ modules/node/init.zsh | 13 ++++++ modules/node/nvm | 1 + 5 files changed, 106 insertions(+) create mode 100644 modules/node/functions/_nvm create mode 160000 modules/node/nvm diff --git a/.gitmodules b/.gitmodules index 7a7a7b5e..9dd21a07 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "modules/completion/external"] path = modules/completion/external url = https://github.com/zsh-users/zsh-completions.git +[submodule "modules/node/nvm"] + path = modules/node/nvm + url = https://github.com/creationix/nvm diff --git a/modules/node/README.md b/modules/node/README.md index 58f2b082..09dbb9c4 100644 --- a/modules/node/README.md +++ b/modules/node/README.md @@ -3,6 +3,8 @@ Node.js 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 --------- @@ -15,9 +17,11 @@ Authors *The authors of this module should be contacted via the [issue tracker][4].* - [Sorin Ionescu](https://github.com/sorin-ionescu) + - [Changwoo Park](https://github.com/pismute) [1]: http://nodejs.org [2]: http://npmjs.org [3]: http://nodejs.org/api [4]: https://github.com/sorin-ionescu/prezto/issues +[5]: https://github.com/creationix/nvm diff --git a/modules/node/functions/_nvm b/modules/node/functions/_nvm new file mode 100644 index 00000000..2f6acc5f --- /dev/null +++ b/modules/node/functions/_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 ' + 'uninstall:Uninstall a ' + 'use:Modify PATH to use ' + 'run:Run with 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 pointing to . Show all aliases beginning with [].' + 'unalias:Deletes the alias named ' + 'copy-packages:Install global NPM packages contained in 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 diff --git a/modules/node/init.zsh b/modules/node/init.zsh index 16847abc..4b41628f 100644 --- a/modules/node/init.zsh +++ b/modules/node/init.zsh @@ -5,6 +5,19 @@ # Sorin Ionescu # +# 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. if (( ! $+commands[node] )); then return 1 diff --git a/modules/node/nvm b/modules/node/nvm new file mode 160000 index 00000000..59c8eda1 --- /dev/null +++ b/modules/node/nvm @@ -0,0 +1 @@ +Subproject commit 59c8eda18c9137c5a06dbfd835658938d9601b8d