Skip to content

Instantly share code, notes, and snippets.

@mxdvl
Forked from sndrs/auto_nvm_use.sh
Last active July 29, 2021 11:34
Show Gist options
  • Save mxdvl/3cfa2db3546658678ca7ca27d35695fa to your computer and use it in GitHub Desktop.
Save mxdvl/3cfa2db3546658678ca7ca27d35695fa to your computer and use it in GitHub Desktop.
Automatically set node version per project using .nvmrc file
# ZSH
autoload -U add-zsh-hook
# place default node version under $HOME/.node-version
load-nvmrc() {
DEFAULT_NODE_VERSION=`cat $HOME/.node-version`
if [[ -f .nvmrc && -r .nvmrc ]]; then
fnm use
elif [[ `node -v` != $DEFAULT_NODE_VERSION ]]; then
echo Reverting to node from "`node -v`" to "$DEFAULT_NODE_VERSION"
fnm use $DEFAULT_NODE_VERSION
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
@mxdvl
Copy link
Author

mxdvl commented Jul 29, 2021

Updated to work with fnm, which is a faster drop-in replacement for nvm.

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