Created
June 6, 2022 01:15
-
-
Save zhangtaihao/3ab0cabf2797101f0164df6eb866359c to your computer and use it in GitHub Desktop.
Auto activate .nvmrc for oh-my-zsh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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