From 185235003e9c395b4989d7bb1d4bc191e98b1130 Mon Sep 17 00:00:00 2001 From: Zeh Rizzatti Date: Thu, 13 Dec 2012 12:10:55 -0300 Subject: [PATCH] Add support for nvm --- modules/node/README.md | 25 ++++++++++++++++++++++++- modules/node/functions/node-info | 25 +++++++++++++++++++++++++ modules/node/init.zsh | 8 +++++++- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 modules/node/functions/node-info diff --git a/modules/node/README.md b/modules/node/README.md index 58f2b08..c0174eb 100644 --- a/modules/node/README.md +++ b/modules/node/README.md @@ -1,13 +1,34 @@ Node.js ======= -Provides utility functions for [Node.js][1] and loads [npm][2] completion. +Provides utility functions for [Node.js][1], loads the Node Version Manager, and +enables [npm][2] completion. + +nvm +--- + +[nvm][5] allows for managing multiple, isolated Node.js installations in the +home directory. Functions --------- - `node-doc` opens the Node.js online [API documentation][3] in the default browser. + - `node-info` exposes information about the Node.js environment via the + `$node_info` associative array. + +Theming +------- + +To display the version number of the current Node.js version, define the +following style inside the `prompt_name_setup` function. + + # %v - Node.js version. + zstyle ':prezto:module:node:info:version' format 'version:%v' + +Then add `$node_info[version]` to either `$PROMPT` or `$RPROMPT` and call +`node-info` in `prompt_name_preexec` hook function. Authors ------- @@ -15,9 +36,11 @@ Authors *The authors of this module should be contacted via the [issue tracker][4].* - [Sorin Ionescu](https://github.com/sorin-ionescu) + - [Zeh Rizzatti](https://github.com/zehrizzatti) [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/node-info b/modules/node/functions/node-info new file mode 100644 index 0000000..2af5042 --- /dev/null +++ b/modules/node/functions/node-info @@ -0,0 +1,25 @@ +# +# Exposes information about the Node.js environment via the $node_info +# associative array. +# +# Authors: +# Zeh Rizzatti +# + +local version +local version_format +local version_formatted + +unset node_info +typeset -gA node_info + +if (( $+functions[nvm_version] )); then + version="${$(nvm_version)#v}" +fi + +if [[ -n "$version" ]]; then + zstyle -s ':prezto:module:node:info:version' format 'version_format' + zformat -f version_formatted "$version_format" "v:$version" + node_info[version]="$version_formatted" +fi + diff --git a/modules/node/init.zsh b/modules/node/init.zsh index 16847ab..904d24d 100644 --- a/modules/node/init.zsh +++ b/modules/node/init.zsh @@ -1,10 +1,16 @@ # -# Completes npm. +# Loads the Node Version Manager and enables npm completion. # # Authors: # Sorin Ionescu +# Zeh Rizzatti # +# Load NVM into the shell session. +if [[ -s "$HOME/.nvm/nvm.sh" ]]; then + source "$HOME/.nvm/nvm.sh" +fi + # Return if requirements are not found. if (( ! $+commands[node] )); then return 1