From 4893128c617cc38bf1ccc4c60de524a69d3e6f8a Mon Sep 17 00:00:00 2001 From: Robert Shuford <75178461+robertshuford@users.noreply.github.com> Date: Thu, 25 Aug 2022 21:12:36 -0400 Subject: [PATCH] [readme] optimize calling of `nvm version` in zsh --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d71451c..07c9199 100644 --- a/README.md +++ b/README.md @@ -613,7 +613,6 @@ Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you e # place this after nvm initialization! autoload -U add-zsh-hook load-nvmrc() { - local node_version="$(nvm version)" local nvmrc_path="$(nvm_find_nvmrc)" if [ -n "$nvmrc_path" ]; then @@ -621,10 +620,10 @@ load-nvmrc() { if [ "$nvmrc_node_version" = "N/A" ]; then nvm install - elif [ "$nvmrc_node_version" != "$node_version" ]; then + elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then nvm use fi - elif [ "$node_version" != "$(nvm version default)" ]; then + elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then echo "Reverting to nvm default version" nvm use default fi