Skip to content

Instantly share code, notes, and snippets.

@geastwood
Created November 10, 2019 09:40
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geastwood/14ccb700840a8b8a8538113eb6d76072 to your computer and use it in GitHub Desktop.
Save geastwood/14ccb700840a8b8a8538113eb6d76072 to your computer and use it in GitHub Desktop.
Auto switch node version based on `.nvmrc` using fnm
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment