Skip to content

Instantly share code, notes, and snippets.

@nivrith
Created October 10, 2020 03:35
Show Gist options
  • Select an option

  • Save nivrith/07cb5e39b0a476adc75a7a6d17e2ae76 to your computer and use it in GitHub Desktop.

Select an option

Save nivrith/07cb5e39b0a476adc75a7a6d17e2ae76 to your computer and use it in GitHub Desktop.
NVM Auto use Bash
#
# Run 'nvm use' automatically every time there's
# a .nvmrc file in the directory. Also, revert to default
# version when entering a directory without .nvmrc
#
enter_directory() {
if [[ $PWD == $PREV_PWD ]]; then
return
fi
PREV_PWD=$PWD
if [[ -f ".nvmrc" ]]; then
nvm use
NVM_DIRTY=true
elif [[ $NVM_DIRTY = true ]]; then
nvm use default
NVM_DIRTY=false
fi
}
export PROMPT_COMMAND=enter_directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment