Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for creationix/nvm inside the node module #343

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions modules/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,43 @@ Node.js

Provides utility functions for [Node.js][1] and loads [npm][2] completion.

nvm
---

Loads [nvm][5], which 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 instance (when nvm is
setup), 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

26 changes: 26 additions & 0 deletions modules/node/functions/node-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# vim: ft=zsh
#
# 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

5 changes: 5 additions & 0 deletions modules/node/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# Sorin Ionescu <[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