djanix
3/20/2018 - 3:34 AM

auto `nvm use`

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