Skip to content

Instantly share code, notes, and snippets.

@nitayneeman
Forked from calendee/.bash_profile
Last active February 24, 2018 12:14
Show Gist options
  • Save nitayneeman/0315a7022cefdea1a89e9a33c2569215 to your computer and use it in GitHub Desktop.
Save nitayneeman/0315a7022cefdea1a89e9a33c2569215 to your computer and use it in GitHub Desktop.
# 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