Skip to content

Instantly share code, notes, and snippets.

@andreasonny83
Last active July 8, 2023 21:34
Show Gist options
  • Save andreasonny83/1ec6b5cdbaf75bb50e52bc4316c35558 to your computer and use it in GitHub Desktop.
Save andreasonny83/1ec6b5cdbaf75bb50e52bc4316c35558 to your computer and use it in GitHub Desktop.
Auto switch Node Version with Nvm
find-nvmrc() {
local dir="$PWD"
while [[ "$dir" != "/" ]]; do
if [[ -f "$dir/.nvmrc" ]]; then
echo "$dir/.nvmrc"
return
fi
dir=$(dirname "$dir")
done
echo ""
}
load-nvmrc() {
local nvmrc_path=$(find-nvmrc)
if [[ -n "$nvmrc_path" ]]; then
nvm use "$(cat "$nvmrc_path")"
fi
}
chpwd() {
load-nvmrc
}
load-nvmrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment