Skip to content

Instantly share code, notes, and snippets.

@zhangtaihao
Created June 6, 2022 01:15
Show Gist options
  • Save zhangtaihao/3ab0cabf2797101f0164df6eb866359c to your computer and use it in GitHub Desktop.
Save zhangtaihao/3ab0cabf2797101f0164df6eb866359c to your computer and use it in GitHub Desktop.
Auto activate .nvmrc for oh-my-zsh
# Track currently active .nvmrc file.
ZSH_NVMRC_ACTIVE=""
autoload -U add-zsh-hook
load-nvmrc() {
# Ignore missing nvm (e.g. wrong load order).
if ! command -v nvm &> /dev/null; then
return
fi
# Find .nvmrc file and activate if changed (fallback to default).
local nvmrc_current="$(nvm_find_nvmrc)"
if [[ $nvmrc_current != $ZSH_NVMRC_ACTIVE ]]; then
if [[ -z $nvmrc_current ]]; then
nvm use default
else
nvm use
fi
ZSH_NVMRC_ACTIVE=$nvmrc_current
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment