Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
NVM Automatic Switching
# 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
    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);
      nvm use default;
# Instructions
- Add the contents of `.bash_profile` to your `~/.bash_profile`.
- In your project directory, `echo X.X.X > .nvmrc` like as `echo 9.4.0 > .nvmrc`
- Now, any time you `cd` into this directory you'll see:
> cd angular-pro-app-seed
Found '/Users/jn/Documents/Apps/my-awesome-project/.nvmrc' with version <9.4.0>
Now using node v9.4.0 (npm v5.6.0)
# Credits
Blake Johnston for the `.bash_profile` script
More details and usage for zsh :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment