Created
November 10, 2019 09:40
-
-
Save geastwood/14ccb700840a8b8a8538113eb6d76072 to your computer and use it in GitHub Desktop.
Auto switch node version based on `.nvmrc` using fnm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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