add first pass at adding NVM to modules
This commit is contained in:
parent
4f19700919
commit
c4dbc3c199
2 changed files with 51 additions and 0 deletions
29
modules/nvm/README.md
Normal file
29
modules/nvm/README.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
NVM
|
||||
====
|
||||
|
||||
Configures [Node][1] local gem installation, loads version managers, and defines
|
||||
aliases.
|
||||
|
||||
NVM
|
||||
---
|
||||
|
||||
[The Node Version Manager (NVM)][2], allows for managing multiple, isolated
|
||||
Node installations and node_modules sets in the home directory.
|
||||
|
||||
#### Auto-Switch
|
||||
|
||||
To enable auto switching the Node version on directory change based on the
|
||||
.nvmrc file, add the following line to *zpreztorc*:
|
||||
|
||||
zstyle ':prezto:module:node:nvm' auto-switch 'yes'
|
||||
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
*The authors of this module should be contacted via the [issue tracker][5].*
|
||||
|
||||
- [Jim Ray](https://github.com/jimiray)
|
||||
|
||||
[1]: https://nodejs.org/en/
|
||||
[2]: https://github.com/creationix/nvm
|
22
modules/nvm/init.zsh
Normal file
22
modules/nvm/init.zsh
Normal file
|
@ -0,0 +1,22 @@
|
|||
### NVM
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
. "/usr/local/opt/nvm/nvm.sh"
|
||||
|
||||
autoload -U add-zsh-hook
|
||||
|
||||
add-zsh-hook chpwd load-nvmrc
|
||||
load-nvmrc
|
||||
|
||||
load-nvmrc() {
|
||||
local node_version="$(nvm version)"
|
||||
local nvmrc_path="$(nvm_find_nvmrc)"
|
||||
if [ -n "$nvmrc_path" ]; then
|
||||
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
|
||||
if [ "$nvmrc_node_version" != "N/A" ] && [ "$nvmrc_node_version" != "$node_version" ]; then
|
||||
nvm use
|
||||
fi
|
||||
elif [ "$node_version" != "$(nvm version default)" ]; then
|
||||
echo "Reverting to nvm default version"
|
||||
nvm use default
|
||||
fi
|
||||
}
|
Loading…
Add table
Reference in a new issue