Skip to content

Instantly share code, notes, and snippets.

@unyo
Created April 14, 2021 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unyo/5b2399c4eb42b8423f99865e65fa020f to your computer and use it in GitHub Desktop.
Save unyo/5b2399c4eb42b8423f99865e65fa020f to your computer and use it in GitHub Desktop.
.zshrc with fnm
# fnm
eval "$(fnm env)"
# add fnm autocomplete
fnm completions --shell=zsh > ~/.config/zsh/completions/_fnm # you can run this once and then comment out
fpath+=~/.config/zsh/completions/_fnm
autoload -U compinit
compinit
# autoload .nvmrc
source ~/auto-node-version-switch.sh
# https://gist.github.com/rockaBe/ad1e2556f84c7b8807acdd2e09063ee0
# 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 ]] || [[ -f .node-version && -r .node-version ]]; 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
@unyo
Copy link
Author

unyo commented Apr 14, 2021

brew install fnm

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