Add load node version when exists .nvmrc file in path

This commit is contained in:
Rafael Antonio Lucio 2017-12-10 00:09:25 -02:00
commit b256f11335

View file

@ -3,3 +3,37 @@
# Load nvm if it exists # Load nvm if it exists
[[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" [[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
# Auto load version node if exists .nvmrc
[[ -n "$ZSH_NVM_AUTOLOAD" ]] || ZSH_NVM_AUTOLOAD=false
load-nvmrc() {
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" ]
then
nvm install
fi
if [ "$nvmrc_node_version" != "$node_version" ]
then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]
then
echo "Reverting to nvm default version"
nvm use default
fi
}
if [[ "$ZSH_NVM_AUTOLOAD" == "true" ]]
then
autoload -U add-zsh-hook
add-zsh-hook chpwd load-nvmrc
load-nvmrc
fi