Created
April 14, 2021 16:09
-
-
Save JacobDB/8514fb871a6dd4d18c2cdf024c8f5ab9 to your computer and use it in GitHub Desktop.
Automatically switch NVM versions when entering directories which contain `.nvmrc`
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
#!/bin/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