mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 22:31:51 +00:00
Alternative way of encountering .nvmrc - lazily load nvm if the node version differs.
This commit is contained in:
parent
7b8af94fc9
commit
d97326c1d5
22
README.md
22
README.md
@ -380,6 +380,28 @@ add-zsh-hook chpwd load-nvmrc
|
|||||||
load-nvmrc
|
load-nvmrc
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Lazy loading `nvm` if the `.nvmrc` version is different to your default
|
||||||
|
|
||||||
|
Alternatively, you can specify a default version of Node to use generally and only load `nvm` if a `.nvmrc` specifies a different version.
|
||||||
|
|
||||||
|
With this technique, you do not initialise `nvm` at the bottom of your `.zshrc`.
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
export PATH=$PATH:/Users/faizn1/.nvm/versions/node/v8.4.0/bin
|
||||||
|
|
||||||
|
function chpwd {
|
||||||
|
if [[ -a .nvmrc ]]; then
|
||||||
|
CURRENT_NVER=`node -v`
|
||||||
|
NVER=`cat .nvmrc`
|
||||||
|
if [ "$CURRENT_NVER" != "$NVER" ]; then
|
||||||
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||||
|
echo "loading nvm so you can use $NVER"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
nvm is released under the MIT license.
|
nvm is released under the MIT license.
|
||||||
|
Loading…
Reference in New Issue
Block a user