Implement .node-version file in Bash & NVM (Also for ZSH!)
30 Aug 13:28

Simply add to your ~/.bashrc:

enter_directory() {
  if [[ $PWD == $PREV_PWD ]]; then return; fi
  PREV_PWD=$PWD
  nodefile=.node-version
  [[ -f "$nodefile" ]] && nvm use $(cat $nodefile)
}
export PROMPT_COMMAND=enter_directory

If you’re using ZSH, place in your ~/.zshrc:

chpwd() {
  if [[ $PWD == $PREV_PWD ]]; then return; fi
  PREV_PWD=$PWD
  nodefile=.node-version
  [[ -a "$nodefile" ]] && nvm use $(cat $nodefile)
}

Comments

Empty! You must sign in to add comments.