Last active
July 8, 2023 21:34
-
-
Save andreasonny83/1ec6b5cdbaf75bb50e52bc4316c35558 to your computer and use it in GitHub Desktop.
Auto switch Node Version with Nvm
This file contains 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
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