Skip to content

Commit

Permalink
Add support for nvm
Browse files Browse the repository at this point in the history
  • Loading branch information
rizzatti authored and lackac committed Jan 19, 2014
1 parent 2429771 commit 9e2d103
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
25 changes: 24 additions & 1 deletion modules/node/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
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
-------

*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

25 changes: 25 additions & 0 deletions modules/node/functions/node-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Exposes information about the Node.js environment via the $node_info
# associative array.
#
# Authors:
# Zeh Rizzatti <[email protected]>
#

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

8 changes: 7 additions & 1 deletion modules/node/init.zsh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#
# Completes npm.
# Loads the Node Version Manager and enables npm completion.
#
# Authors:
# Sorin Ionescu <[email protected]>
# Zeh Rizzatti <[email protected]>
#

# 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
Expand Down

0 comments on commit 9e2d103

Please sign in to comment.