Skip to content

Instantly share code, notes, and snippets.

@djanix
Created March 20, 2018 03:34
Show Gist options
  • Save djanix/5405136c7513b0df5f371a9d4a2dbbb3 to your computer and use it in GitHub Desktop.
Save djanix/5405136c7513b0df5f371a9d4a2dbbb3 to your computer and use it in GitHub Desktop.
auto `nvm use`
# NVM version shortcut
# change title name of tab in terminal
function title {
echo -ne "\033]0;"$*"\007"
}
cd() {
builtin cd "$@" || return
#echo $PREV_PWD
if [ "$PWD" != "$PREV_PWD" ]; then
PREV_PWD="$PWD";
title $(echo ${PWD##*/}) $(node -v);
if [ -e ".nvmrc" ]; then
nvm use;
# set tab terminal name to be cwd and node version
title $(echo ${PWD##*/}) $(node -v);
else
nvm use default;
fi
fi
}
# Credits:
# Justin Noel for the gist
# Blake Johnston for the `.bash_profile` script
# More details and usage for zsh : https://medium.com/@kinduff/automatic-version-switch-for-nvm-ff9e00ae67f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment