Skip to content

Instantly share code, notes, and snippets.

@fadlee
Created December 16, 2021 23:15
Show Gist options
  • Save fadlee/d4013fcfa3aa1920fd14f632136b2058 to your computer and use it in GitHub Desktop.
Save fadlee/d4013fcfa3aa1920fd14f632136b2058 to your computer and use it in GitHub Desktop.
Auto switch node version using fnm with zsh shell
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