From 1d40a5bc8b29467b56b727fd796966cf0b1b8249 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Mon, 17 Mar 2014 13:16:12 +0100 Subject: [PATCH 1/2] Replaced echo for printf when using formatted strings Updated version list, now also compatible with zsh --- nvm.sh | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/nvm.sh b/nvm.sh index a368ac1..3b4f133 100644 --- a/nvm.sh +++ b/nvm.sh @@ -26,9 +26,6 @@ if [ ! -d "$NVM_DIR" ]; then fi fi -DASH_E="" -[ -z "$(echo -n -e)" ] && DASH_E="-e" - # Setup mirror location if not already set if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist" @@ -140,24 +137,19 @@ nvm_checksum() { fi } -colorize_version() { - if [ -n "$DASH_E" ]; then - echo $DASH_E "\033[0;34m$1\033[0m" - else - echo $1 - fi -} - print_versions() { local VERSION - local PADDED_VERSION - for VERSION in $1; do - PADDED_VERSION=`printf '%10s' $VERSION` - if [ -d "$NVM_DIR/$VERSION" ]; then - colorize_version "$PADDED_VERSION" + local FORMAT + local CURRENT=`nvm_version current` + echo "$1" | while read VERSION; do + if [ "$VERSION" == "$CURRENT" ]; then + FORMAT='\033[0;32m-> %9s\033[0m' + elif [ -d "$NVM_DIR/$VERSION" ]; then + FORMAT='\033[0;34m%12s\033[0m' else - echo "$PADDED_VERSION" + FORMAT='%12s' fi + printf "$FORMAT\n" $VERSION done } @@ -475,7 +467,6 @@ nvm() { "ls" | "list" ) print_versions "`nvm_ls $2`" if [ $# -eq 1 ]; then - printf "current: \t"; nvm_version current nvm alias fi return @@ -485,7 +476,7 @@ nvm() { return ;; "current" ) - echo $DASH_E -n "current: \t"; nvm_version current + nvm_version current ;; "alias" ) mkdir -p $NVM_DIR/alias @@ -548,7 +539,7 @@ nvm() { echo "Cache cleared." ;; "version" ) - colorize_version "`nvm_version $2`" + nvm_version $2 ;; * ) nvm help From 70f1734c120de6ec895b82896c3c1f80fe74727d Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Mon, 17 Mar 2014 13:24:24 +0100 Subject: [PATCH 2/2] updated tests for altered output --- ...ing \"nvm current\" should display current nvm environment." | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a2c93a5..1eedaf6 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,4 @@ die () { echo $@ ; exit 1; } . ../../nvm.sh -[ `expr "$(nvm current)" : ".*current"` != 0 ] || die "Failed to find current version" +[ "$(nvm current)" == `node -v` ] || die "Failed to find current version"