accerlate nvm invoke when change directory

sunxiaobo 2016-10-13 16:02:28 +08:00
parent 4b88613508
commit a338f98a5a
1 changed files with 10 additions and 3 deletions

View File

@ -316,9 +316,16 @@ Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you e
# place this after nvm initialization! # place this after nvm initialization!
autoload -U add-zsh-hook autoload -U add-zsh-hook
load-nvmrc() { load-nvmrc() {
if [[ -f .nvmrc && -r .nvmrc ]]; then local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" != "N/A" ] && [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use nvm use
elif [[ $(nvm version) != $(nvm version default) ]]; then fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version" echo "Reverting to nvm default version"
nvm use default nvm use default
fi fi