Skip to content

Instantly share code, notes, and snippets.

@sandinmyjoints
Created April 15, 2016 21:07
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 sandinmyjoints/31ba725b6ba31b9d3121b7602827f6df to your computer and use it in GitHub Desktop.
Save sandinmyjoints/31ba725b6ba31b9d3121b7602827f6df to your computer and use it in GitHub Desktop.
Call nvm use as needed according to .nvmrc file
function nvm_use_if_needed () {
[[ -r ./.nvmrc && -s ./.nvmrc ]] || return
WANTED=$(sed 's/v//' < ./.nvmrc)
CURRENT=$(hash node 2>/dev/null && node -v | sed 's/v//')
if [ "$WANTED" != "$CURRENT" ]; then
nvm use
fi
}
export PROMPT_COMMAND="$PROMPT_COMMAND ; nvm_use_if_needed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment