Skip to content

Commit 4893128

Browse files
robertshufordljharb
authored andcommitted
[readme] optimize calling of nvm version in zsh
1 parent 8fd9480 commit 4893128

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,18 +613,17 @@ Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you e
613613
# place this after nvm initialization!
614614
autoload -U add-zsh-hook
615615
load-nvmrc() {
616-
local node_version="$(nvm version)"
617616
local nvmrc_path="$(nvm_find_nvmrc)"
618617
619618
if [ -n "$nvmrc_path" ]; then
620619
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
621620
622621
if [ "$nvmrc_node_version" = "N/A" ]; then
623622
nvm install
624-
elif [ "$nvmrc_node_version" != "$node_version" ]; then
623+
elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then
625624
nvm use
626625
fi
627-
elif [ "$node_version" != "$(nvm version default)" ]; then
626+
elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then
628627
echo "Reverting to nvm default version"
629628
nvm use default
630629
fi

0 commit comments

Comments
 (0)