From 9912f7cc460dcdf0fad568f5bdb6092f2a671177 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 14 Jul 2014 11:17:26 -0700 Subject: [PATCH] If nvm is deactivated, display "none" or "system" instead of the system node version --- nvm.sh | 10 +++++++++- ... current\" should display current nvm environment." | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index cdafa78..a0dc370 100644 --- a/nvm.sh +++ b/nvm.sh @@ -160,7 +160,15 @@ nvm_binary_available() { } nvm_ls_current() { - echo `node -v 2>/dev/null` + local NODE_PATH + NODE_PATH="$(which node)" + if [ $? -ne 0 ]; then + echo 'none' + elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then + echo `node -v 2>/dev/null` + else + echo 'system' + fi } nvm_ls() { diff --git "a/test/fast/Running \"nvm current\" should display current nvm environment." "b/test/fast/Running \"nvm current\" should display current nvm environment." index d9293ed..5748fd6 100755 --- "a/test/fast/Running \"nvm current\" should display current nvm environment." +++ "b/test/fast/Running \"nvm current\" should display current nvm environment." @@ -3,4 +3,8 @@ die () { echo $@ ; exit 1; } . ../../nvm.sh -[ "$(nvm current)" = "$(node -v)" ] || die "Failed to find current version" + +nvm deactivate 2>&1 + +[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated' +