From 42b010775b95455c8ff1f3b17c29f1a2af4644ed Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 14 Jul 2014 11:42:10 -0700 Subject: [PATCH 1/4] Add `system` support to `nvm_print_versions` --- nvm.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nvm.sh b/nvm.sh index 609474d..cc3f4d2 100644 --- a/nvm.sh +++ b/nvm.sh @@ -251,6 +251,8 @@ nvm_print_versions() { FORMAT='\033[0;32m-> %9s\033[0m' elif [ -d "$NVM_DIR/$VERSION" ]; then FORMAT='\033[0;34m%12s\033[0m' + elif [ "$VERSION" = "system" ]; then + FORMAT='\033[0;33m%12s\033[0m' else FORMAT='%12s' fi From 6e02e5a54ce2314cb770de629e02a3c554bd89d2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 14 Jul 2014 11:38:26 -0700 Subject: [PATCH 2/4] If `nvm_ls` is called without a pattern, and node exists, tack on "system". --- nvm.sh | 3 +++ ...hould include \"system\" when appropriate" | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100755 "test/fast/Listing versions/Running \"nvm ls\" should include \"system\" when appropriate" diff --git a/nvm.sh b/nvm.sh index cc3f4d2..cdafa78 100644 --- a/nvm.sh +++ b/nvm.sh @@ -194,6 +194,9 @@ nvm_ls() { echo "N/A" return 3 fi + if [ -z "$PATTERN" ] && nvm_has_system_node; then + VERSIONS="$VERSIONS$(printf '\n%s' 'system')" + fi echo "$VERSIONS" return } diff --git "a/test/fast/Listing versions/Running \"nvm ls\" should include \"system\" when appropriate" "b/test/fast/Listing versions/Running \"nvm ls\" should include \"system\" when appropriate" new file mode 100755 index 0000000..9afd40a --- /dev/null +++ "b/test/fast/Listing versions/Running \"nvm ls\" should include \"system\" when appropriate" @@ -0,0 +1,21 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +mkdir -p ../../../v0.0.1 +mkdir -p ../../../v0.0.3 +mkdir -p ../../../v0.0.9 +mkdir -p ../../../v0.3.1 +mkdir -p ../../../v0.3.3 +mkdir -p ../../../v0.3.9 + +nvm_has_system_node() { return 0; } +nvm ls | grep system 2>&1 > /dev/null +[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present' + +nvm_has_system_node() { return 1; } +nvm ls | grep system 2>&1 > /dev/null +[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present' + From 9912f7cc460dcdf0fad568f5bdb6092f2a671177 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 14 Jul 2014 11:17:26 -0700 Subject: [PATCH 3/4] 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' + From e7ada80d084d8a58168996462da6972509bc3b09 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 14 Jul 2014 11:49:49 -0700 Subject: [PATCH 4/4] `nvm use system` should work as expected. --- nvm.sh | 12 +++++++++++- ...ning \"nvm use system\" should work as expected" | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 "test/fast/Running \"nvm use system\" should work as expected" diff --git a/nvm.sh b/nvm.sh index a0dc370..d0335e1 100644 --- a/nvm.sh +++ b/nvm.sh @@ -550,7 +550,17 @@ nvm() { VERSION=`nvm_version $NVM_RC_VERSION` fi else - VERSION=`nvm_version $2` + if [ $2 = 'system' ]; then + if nvm_has_system_node && nvm deactivate; then + echo "Now using system version of node: $(node -v 2>/dev/null)." + return + else + echo "System version of node not found." >&2 + return 127 + fi + else + VERSION=`nvm_version $2` + fi fi if [ -z "$VERSION" ]; then nvm help diff --git "a/test/fast/Running \"nvm use system\" should work as expected" "b/test/fast/Running \"nvm use system\" should work as expected" new file mode 100755 index 0000000..9b4e850 --- /dev/null +++ "b/test/fast/Running \"nvm use system\" should work as expected" @@ -0,0 +1,13 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../nvm.sh + +nvm_has_system_node() { return 0; } +[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node" + +nvm_has_system_node() { return 1; } +[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found" +nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" +