mirror of
https://github.com/lukechilds/zsh-nvm.git
synced 2025-06-05 11:56:28 +08:00
Merge a430aab4f9
into 745291dcf2
This commit is contained in:
commit
e8f02d2fac
@ -163,22 +163,57 @@ _zsh_nvm_revert() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_current_node_version() {
|
||||||
|
if _node_is_nvm; then
|
||||||
|
node --version 2>/dev/null
|
||||||
|
else
|
||||||
|
printf 'system'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_node_is_nvm() {
|
||||||
|
local node_path="$(command which node 2>/dev/null)"
|
||||||
|
if [[ -n "$node_path" && -z "${node_path##$NVM_DIR*}" ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_nvm_default_version() {
|
||||||
|
local alias="$(nvm_resolve_alias default)"
|
||||||
|
if [[ "$alias" = 'node' ]]; then
|
||||||
|
nvm_ls node | nvm_grep -e '^v' | nvm_grep -v -e "^v0" | tail -n 1
|
||||||
|
else
|
||||||
|
nvm version default
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
autoload -U add-zsh-hook
|
autoload -U add-zsh-hook
|
||||||
_zsh_nvm_auto_use() {
|
_zsh_nvm_auto_use() {
|
||||||
_zsh_nvm_has nvm_find_nvmrc || return
|
_zsh_nvm_has nvm_find_nvmrc || return
|
||||||
|
if [[ $NVM_AUTO_USE != 'true' ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
local node_version="$(nvm version)"
|
local node_version="$(_current_node_version)"
|
||||||
local nvmrc_path="$(nvm_find_nvmrc)"
|
local nvmrc_path="$(nvm_find_nvmrc)"
|
||||||
|
|
||||||
if [[ -n "$nvmrc_path" ]]; then
|
if [[ -n "$nvmrc_path" ]]; then
|
||||||
|
local nvmrc_dir="$(dirname "$nvmrc_path")"
|
||||||
|
local nvmrc_version="$(cat "$nvmrc_path")"
|
||||||
local nvmrc_node_version="$(nvm version $(cat "$nvmrc_path"))"
|
local nvmrc_node_version="$(nvm version $(cat "$nvmrc_path"))"
|
||||||
|
|
||||||
if [[ "$nvmrc_node_version" = "N/A" ]]; then
|
if [[ -v NVM_AUTO_USE_IGNORE_VERSION ]] && [[ ${NVM_AUTO_USE_IGNORE_VERSION[(Ie)$nvmrc_version]} -gt 0 ]]; then
|
||||||
|
echo "Detected nvm version <$nvmrc_version>, but this version is set to be ignored"
|
||||||
|
elif [[ -v NVM_AUTO_USE_IGNORE_PATH ]] && [[ ${NVM_AUTO_USE_IGNORE_PATH[(Ie)$nvmrc_dir]} -gt 0 ]]; then
|
||||||
|
echo "Detected nvm version <$nvmrc_version>, but this path is set to be ignored"
|
||||||
|
elif [[ "$nvmrc_node_version" = "N/A" ]]; then
|
||||||
nvm install && export NVM_AUTO_USE_ACTIVE=true
|
nvm install && export NVM_AUTO_USE_ACTIVE=true
|
||||||
elif [[ "$nvmrc_node_version" != "$node_version" ]]; then
|
elif [[ "$nvmrc_node_version" != "$node_version" ]]; then
|
||||||
nvm use && export NVM_AUTO_USE_ACTIVE=true
|
nvm use && export NVM_AUTO_USE_ACTIVE=true
|
||||||
fi
|
fi
|
||||||
elif [[ "$node_version" != "$(nvm version default)" ]] && [[ "$NVM_AUTO_USE_ACTIVE" = true ]]; then
|
elif [[ "$NVM_AUTO_USE_ACTIVE" = true ]] && [[ "$node_version" != "$(_nvm_default_version)" ]]; then
|
||||||
echo "Reverting to nvm default version"
|
echo "Reverting to nvm default version"
|
||||||
nvm use default
|
nvm use default
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user