From 91a29c0da2bc1986fdab5f4a77a0b20302d4896c Mon Sep 17 00:00:00 2001 From: mail6543210 Date: Mon, 20 Nov 2017 22:31:12 +0800 Subject: [PATCH 1/3] Fix for $path used by zsh "The lower-case version of PATH is an array parameter bound to the scalar upper-case parameter." -- http://www.zsh.org/mla/users/2015/msg00178.html --- nvm.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nvm.sh b/nvm.sh index 472b20d..dd4f884 100644 --- a/nvm.sh +++ b/nvm.sh @@ -273,12 +273,12 @@ nvm_tree_contains_path() { # Traverse up in directory tree to find containing folder nvm_find_up() { - local path - path="${PWD}" - while [ "${path}" != "" ] && [ ! -f "${path}/${1-}" ]; do - path=${path%/*} + local path_ + path_="${PWD}" + while [ "${path_}" != "" ] && [ ! -f "${path_}/${1-}" ]; do + path_=${path_%/*} done - nvm_echo "${path}" + nvm_echo "${path_}" } From 16d3e6d2dce4c38de0acfe0a51fd142c9a8e9b3b Mon Sep 17 00:00:00 2001 From: mail6543210 Date: Tue, 21 Nov 2017 23:44:38 +0800 Subject: [PATCH 2/3] Remove unnecessary, incorrect workaround. The "\printf" calls zsh shell builtin instead of `command printf` in scripting. The workaround is no longer needed given 91a29c0. --- nvm.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/nvm.sh b/nvm.sh index dd4f884..be5e733 100644 --- a/nvm.sh +++ b/nvm.sh @@ -13,13 +13,7 @@ NVM_SCRIPT_SOURCE="$_" nvm_echo() { - command printf %s\\n "$*" 2>/dev/null || { - nvm_echo() { - # shellcheck disable=SC1001 - \printf %s\\n "$*" # on zsh, `command printf` sometimes fails - } - nvm_echo "$@" - } + command printf %s\\n "$*" 2>/dev/null } nvm_cd() { From 9352f6913a2690905e1a9e91eb634911ec09a7c8 Mon Sep 17 00:00:00 2001 From: mail6543210 Date: Wed, 22 Nov 2017 01:53:46 +0800 Subject: [PATCH 3/3] Add symbolic link for printf in case of command-not-found --- test/fast/Unit tests/nvm_ls_current | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fast/Unit tests/nvm_ls_current b/test/fast/Unit tests/nvm_ls_current index 8ed8020..0e44b20 100755 --- a/test/fast/Unit tests/nvm_ls_current +++ b/test/fast/Unit tests/nvm_ls_current @@ -21,6 +21,7 @@ rm -rf "$TEST_DIR" mkdir "$TEST_DIR" ln -s "$(command which which)" "$TEST_DIR/which" ln -s "$(command which dirname)" "$TEST_DIR/dirname" +ln -s "$(command which printf)" "$TEST_DIR/printf" [ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"' [ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output'