Skip to content

Instantly share code, notes, and snippets.

@Mazuh
Created August 13, 2023 19:45
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 Mazuh/50e47465a6b2139e764c2500c01260bc to your computer and use it in GitHub Desktop.
Save Mazuh/50e47465a6b2139e764c2500c01260bc to your computer and use it in GitHub Desktop.
"NVM use" after entering each directory
# 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="$PROMPT_COMMAND; enter_directory"
prmptcmd() { eval "$PROMPT_COMMAND" }
precmd_functions=(prmptcmd)
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment