|
@@ -35,6 +35,33 @@ if (( $+NVM_LAZY )); then
|
|
|
}
|
|
|
fi
|
|
|
|
|
|
+# Autoload nvm when finding a .nvmrc file in the current directory
|
|
|
+# Adapted from: https://github.com/nvm-sh/nvm#zsh
|
|
|
+if (( $+NVM_AUTOLOAD )); then
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ autoload -U add-zsh-hook
|
|
|
+ add-zsh-hook chpwd load-nvmrc
|
|
|
+
|
|
|
+ load-nvmrc
|
|
|
+fi
|
|
|
+
|
|
|
# Load nvm bash completion
|
|
|
for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
|
|
|
if [[ -f "$nvm_completion" ]]; then
|
|
@@ -47,4 +74,4 @@ for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_complet
|
|
|
fi
|
|
|
done
|
|
|
|
|
|
-unset NVM_HOMEBREW NVM_LAZY nvm_completion
|
|
|
+unset NVM_HOMEBREW NVM_LAZY NVM_AUTOLOAD nvm_completion
|