Skip to content

Instantly share code, notes, and snippets.

@leeadkins
Created October 1, 2012 02:52
Show Gist options
  • Save leeadkins/3809218 to your computer and use it in GitHub Desktop.
Save leeadkins/3809218 to your computer and use it in GitHub Desktop.
Super simple hack to automatically switch to a specific Node version on CD (using NVM and ZSH)
# Detects if a .nvmrc file exists, and switches
# to the specified version if it does.
# The contents of the .nvmrc file should simply be the node
# version to use, like "v0.8.11"
# Put this in your .zshrc file or somewhere else that is loaded automatically
function chpwd() {
emulate -L zsh
if [[ -f .nvmrc ]] then
nvm use `cat .nvmrc`
fi
}
@ShirajG
Copy link

ShirajG commented Jun 3, 2015

You don't need to cat the contents of the nvmrc file into nvm use, the default behavior of nvm use is to look for a nvmrc file and use that, so you could just do:

function chpwd() {
  emulate -L zsh
  if [[ -f .nvmrc ]] then
    nvm use
  fi
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment