Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alwayrun/38ca5bb35a22451dec469f04671d30a5 to your computer and use it in GitHub Desktop.
Save alwayrun/38ca5bb35a22451dec469f04671d30a5 to your computer and use it in GitHub Desktop.
# Put this into your $HOME/.zshrc to call nvm use automatically whenever you enter a directory that contains an .nvmrc file with a string telling nvm which node to use:
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use
elif [[ $(nvm version) != $(nvm version default) ]]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
@pgrantmartello
Copy link

https://github.com/tomsquest/nvm-auto-use.zsh/blob/master/nvm-auto-use.zsh

This had an interesting addition to this script; if you don't have the .nvmrc version installed, it installed it for you. Just something to consider :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment