mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-01 04:30:37 +02:00
27 lines
766 B
Bash
27 lines
766 B
Bash
# Set NVM_DIR if it isn't already defined
|
|
[[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm"
|
|
|
|
# Load nvm if it exists
|
|
[[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
|
|
|
|
# Taken from: https://github.com/creationix/nvm#zsh
|
|
autoload -U add-zsh-hook
|
|
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
|
|
elif [ "$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
|
|
}
|
|
add-zsh-hook chpwd load-nvmrc
|
|
load-nvmrc#
|