Skip to content

Instantly share code, notes, and snippets.

@dlee
Created October 9, 2017 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlee/98a7cd0fd012099466ca1b13ae0fd308 to your computer and use it in GitHub Desktop.
Save dlee/98a7cd0fd012099466ca1b13ae0fd308 to your computer and use it in GitHub Desktop.
export SKIP_INSTALL_AVN="Y"
export NVM_DIR="$HOME/.nvm"
# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
if [ -s "$NVM_DIR/nvm.sh" ]; then
# https://github.com/creationix/nvm/blob/d91b6197f3f60e1e7a332acf69a9b90e83120f06/nvm.sh#L265-L282
# https://github.com/creationix/nvm#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file
load_nvmrc() {
local dir="${PWD}"
while [ -n "${dir}" ]; do
[ -e "${dir}/.nvmrc" ] && break
dir=${dir%/*}
done
local nvmrc_path="${dir}/.nvmrc"
if [ -e "$nvmrc_path" ]; then
which nvm > /dev/null || source "$NVM_DIR/nvm.sh"
[ $(nvm version "$(cat "${nvmrc_path}")") != $(nvm version) ] && nvm use
elif [ -n "$NVM_BIN" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd load_nvmrc
load_nvmrc
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment