Created
December 16, 2021 23:15
-
-
Save fadlee/d4013fcfa3aa1920fd14f632136b2058 to your computer and use it in GitHub Desktop.
Auto switch node version using fnm with zsh shell
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
eval "`fnm env`" | |
# do this after eval fnm env | |
auto-fnm-use() { | |
if [[ -f .nvmrc && -r .nvmrc ]] || [[ -f .node-version && -r .node-version ]]; then | |
fnm use | |
elif [[ `node -v` != `~/.fnm/aliases/default/bin/node -v` ]]; then | |
echo Reverting to node from "`node -v`" to "`~/.fnm/aliases/default/bin/node -v`" | |
fnm use default | |
fi | |
} | |
add-zsh-hook chpwd auto-fnm-use | |
auto-fnm-use |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment