From 9a0c2697137a72b1d7e3aba502654bcee3d2c881 Mon Sep 17 00:00:00 2001 From: "Dr. Kibitz" Date: Tue, 18 Feb 2014 21:51:39 -0800 Subject: [PATCH 01/16] Redo https://github.com/creationix/nvm/pull/345 --- nvm.sh | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/nvm.sh b/nvm.sh index 2f60317..d185a17 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1,5 +1,3 @@ -#!/bin/sh - # Node Version Manager # Implemented as a bash function # To use source this file from your bash profile @@ -21,7 +19,11 @@ fi # Auto detect the NVM_DIR if [ ! -d "$NVM_DIR" ]; then - export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd) + if [ -n "$BASH_SOURCE" ]; then + export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd) + else + export NVM_DIR=$HOME/.nvm + fi fi # Setup mirror location if not already set @@ -33,7 +35,7 @@ nvm_set_nullglob() { if has "setopt"; then # Zsh setopt NULL_GLOB - else + elif has "shopt"; then # Bash shopt -s nullglob fi @@ -88,7 +90,7 @@ nvm_ls() { return fi # If it looks like an explicit version, don't do anything funny - if [[ "$PATTERN" == v?*.?*.?* ]]; then + if [ `expr "$PATTERN" : "v.*.\?.*.\?.*$"` != 0 ]; then VERSIONS="$PATTERN" else VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "v$PATTERN*" -exec basename '{}' ';' \ @@ -98,7 +100,7 @@ nvm_ls() { echo "N/A" return fi - echo "$VERSIONS" + printf "$VERSIONS\n" return } @@ -146,7 +148,7 @@ print_versions() { local PADDED_VERSION for VERSION in $1; do PADDED_VERSION=`printf '%10s' $VERSION` - if [[ -d "$NVM_DIR/$VERSION" ]]; then + if [ -d "$NVM_DIR/$VERSION" ]; then colorize_version "$PADDED_VERSION" else echo "$PADDED_VERSION" @@ -331,10 +333,10 @@ nvm() { nvm use $VERSION if ! has "npm" ; then echo "Installing npm..." - if [[ "`expr match $VERSION '\(^v0\.1\.\)'`" != '' ]]; then + if [ "`expr match $VERSION '\(^v0\.1\.\)'`" != '' ]; then echo "npm requires node v0.2.3 or higher" - elif [[ "`expr match $VERSION '\(^v0\.2\.\)'`" != '' ]]; then - if [[ "`expr match $VERSION '\(^v0\.2\.[0-2]$\)'`" != '' ]]; then + elif [ "`expr match $VERSION '\(^v0\.2\.\)'`" != '' ]; then + if [ "`expr match $VERSION '\(^v0\.2\.[0-2]$\)'`" != '' ]; then echo "npm requires node v0.2.3 or higher" else curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh @@ -350,7 +352,7 @@ nvm() { ;; "uninstall" ) [ $# -ne 2 ] && nvm help && return - if [[ $2 == `nvm_version` ]]; then + if [ $2 == `nvm_version` ]; then echo "nvm: Cannot uninstall currently-active node version, $2." return 1 fi @@ -378,14 +380,14 @@ nvm() { ;; "deactivate" ) - if [[ $PATH == *$NVM_DIR/*/bin* ]]; then + if [ `expr $PATH : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:} hash -r echo "$NVM_DIR/*/bin removed from \$PATH" else echo "Could not find $NVM_DIR/*/bin in \$PATH" fi - if [[ $MANPATH == *$NVM_DIR/*/share/man* ]]; then + if [ `expr $MANPATH : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then export MANPATH=${MANPATH%$NVM_DIR/*/share/man*}${MANPATH#*$NVM_DIR/*/share/man:} echo "$NVM_DIR/*/share/man removed from \$MANPATH" else @@ -422,7 +424,7 @@ nvm() { echo "$VERSION version is not installed yet" return 1 fi - if [[ $PATH == *$NVM_DIR/*/bin* ]]; then + if [ `expr $PATH : ".*$NVM_DIR/.*/bin"` != 0 ]; then PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$VERSION/bin${PATH#*$NVM_DIR/*/bin} else PATH="$NVM_DIR/$VERSION/bin:$PATH" @@ -431,7 +433,7 @@ nvm() { MANPATH=$(manpath) fi MANPATH=${MANPATH#*$NVM_DIR/*/man:} - if [[ $MANPATH == *$NVM_DIR/*/share/man* ]]; then + if [ `expr $MANPATH : ".*$NVM_DIR/.*/share/man"` != 0 ]; then MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$VERSION/share/man${MANPATH#*$NVM_DIR/*/share/man} else MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH" @@ -471,7 +473,7 @@ nvm() { "ls" | "list" ) print_versions "`nvm_ls $2`" if [ $# -eq 1 ]; then - echo -ne "current: \t"; nvm_version current + printf "current: \t"; nvm_version current nvm alias fi return @@ -533,7 +535,7 @@ nvm() { # declare local INSTALLS first, otherwise it doesn't work in zsh local INSTALLS - INSTALLS=( `nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "` ) + INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "` npm install -g ${INSTALLS[@]} ;; @@ -550,5 +552,5 @@ nvm() { esac } -nvm ls default &>/dev/null && nvm use default >/dev/null || true +nvm ls default >/dev/null && nvm use default >/dev/null || true From a9be598241410216b2264b74fc0a1b12482c1b1f Mon Sep 17 00:00:00 2001 From: "Dr. Kibitz" Date: Tue, 18 Feb 2014 21:57:52 -0800 Subject: [PATCH 02/16] Remove some new bashisms --- nvm.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index d185a17..178aada 100755 --- a/nvm.sh +++ b/nvm.sh @@ -393,7 +393,7 @@ nvm() { else echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" fi - if [[ $NODE_PATH == *$NVM_DIR/*/lib/node_modules* ]]; then + if [ `expr $NODE_PATH : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then export NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}${NODE_PATH#*$NVM_DIR/*/lib/node_modules:} echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" else @@ -438,7 +438,7 @@ nvm() { else MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH" fi - if [[ $NODE_PATH == *$NVM_DIR/*/lib/node_modules* ]]; then + if [ `expr $NODE_PATH : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules} else NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH" @@ -462,7 +462,7 @@ nvm() { echo "$VERSION version is not installed yet" return; fi - if [[ $NODE_PATH == *$NVM_DIR/*/lib/node_modules* ]]; then + if [ `expr $NODE_PATH : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then RUN_NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules} else RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH" From 0f709eafa0db917d9a9c2a6e233d7eb8608abc72 Mon Sep 17 00:00:00 2001 From: "Dr. Kibitz" Date: Tue, 18 Feb 2014 22:07:25 -0800 Subject: [PATCH 03/16] Missed tests --- ...ing \"nvm ls\" should display all installed versions." | 8 ++++++-- ...nvm current\" should display current nvm environment." | 2 +- ...ctivate\" should unset the nvm environment variables." | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git "a/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." "b/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." index dfba0da..be0dddb 100755 --- "a/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." +++ "b/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." @@ -2,8 +2,12 @@ . ../../../nvm.sh -mkdir ../../../v0.0.{1,3,9} -mkdir ../../../v0.3.{1,3,9} +mkdir ../../../v0.0.1 +mkdir ../../../v0.0.3 +mkdir ../../../v0.0.9 +mkdir ../../../v0.3.1 +mkdir ../../../v0.3.3 +mkdir ../../../v0.3.9 # The result should contain the version numbers. nvm ls | grep v0.0.1 && 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 09b8931..40d528f 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 -[[ $(nvm current) == *"current"* ]] || die "Failed to find current version" +[ `expr "$(nvm current)" : ".*current"` != 0 ] || die "Failed to find current version" \ No newline at end of file diff --git "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." index 0f2ad3b..813f226 100755 --- "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." +++ "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." @@ -4,11 +4,11 @@ mkdir -p ../../v0.2.3 die () { echo $@ ; exit 1; } -[[ $PATH != *v0.2.3/*/bin* ]] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 +[ `expr $PATH : ".*v0.2.3/.*/bin"` == 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 . ../../nvm.sh nvm use v0.2.3 && -[[ $PATH == *v0.2.3/*/bin* ]] || die "Failed to activate v0.2.3" +[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] || die "Failed to activate v0.2.3" nvm deactivate && -[[ $PATH != *v0.2.3/*/bin* ]] || die "Failed to deactivate v0.2.3" +[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] || die "Failed to deactivate v0.2.3" From 8925419e90123e5432e9a84ddd90a5f186e4d420 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 21 Feb 2014 19:21:03 +1000 Subject: [PATCH 04/16] tests: avoid reliance on nullglob Some shells do not have a nullglob feature, including dash (default /bin/sh on Ubuntu) and the Almquist shell (default /bin/sh on FreeBSD). An mv(1) command in setup_dir is failing due to a glob not matching anything, so use a more widely supported construction. --- test/fast/setup_dir | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/fast/setup_dir b/test/fast/setup_dir index 75e67e3..64e097c 100755 --- a/test/fast/setup_dir +++ b/test/fast/setup_dir @@ -5,8 +5,9 @@ # Back up - type setopt >/dev/null 2>&1 && setopt NULL_GLOB - type shopt >/dev/null 2>&1 && shopt -s nullglob mkdir -p bak - mv v* src alias bak || sleep 0s + for SRC in v* src alias; do + [ -e "$SRC" ] && mv "$SRC" bak + done + true ) From ee6d4ab0749e6c5772ef05a4e67fdcdd1f14d771 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 21 Feb 2014 20:18:57 +1000 Subject: [PATCH 05/16] fix ls command in dash The `colorize_version` command fails in dash (default /bin/sh on Ubuntu) with an error like: local: v0.2.3: bad variable name Instead of using a local variable, interpolate the function argument directly to avoid the error. --- nvm.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 178aada..f40ac07 100755 --- a/nvm.sh +++ b/nvm.sh @@ -139,8 +139,7 @@ nvm_checksum() { } colorize_version() { - local VERSION=$1 - echo -e "\033[0;34m$VERSION\033[0m" + echo -e "\033[0;34m$1\033[0m" } print_versions() { From 4a5f5203d04086d7fb77b09aac6171881a787b5c Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 21 Feb 2014 20:52:50 +1000 Subject: [PATCH 06/16] fix errors and portability issues in expr commands Add double-quotes around all expr(1) left-hand-sides where the argument is just a variable, to prevent syntax errors when the variable is empty. Also avoid the `expr match ...` variant as this is not defined in POSIX and causes errors in some implementations, including FreeBSD's. --- nvm.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/nvm.sh b/nvm.sh index f40ac07..8455c69 100755 --- a/nvm.sh +++ b/nvm.sh @@ -332,10 +332,10 @@ nvm() { nvm use $VERSION if ! has "npm" ; then echo "Installing npm..." - if [ "`expr match $VERSION '\(^v0\.1\.\)'`" != '' ]; then + if [ "`expr "$VERSION" : '\(^v0\.1\.\)'`" != '' ]; then echo "npm requires node v0.2.3 or higher" - elif [ "`expr match $VERSION '\(^v0\.2\.\)'`" != '' ]; then - if [ "`expr match $VERSION '\(^v0\.2\.[0-2]$\)'`" != '' ]; then + elif [ "`expr "$VERSION" : '\(^v0\.2\.\)'`" != '' ]; then + if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then echo "npm requires node v0.2.3 or higher" else curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh @@ -379,20 +379,20 @@ nvm() { ;; "deactivate" ) - if [ `expr $PATH : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then + if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:} hash -r echo "$NVM_DIR/*/bin removed from \$PATH" else echo "Could not find $NVM_DIR/*/bin in \$PATH" fi - if [ `expr $MANPATH : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then + if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then export MANPATH=${MANPATH%$NVM_DIR/*/share/man*}${MANPATH#*$NVM_DIR/*/share/man:} echo "$NVM_DIR/*/share/man removed from \$MANPATH" else echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" fi - if [ `expr $NODE_PATH : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then + if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then export NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}${NODE_PATH#*$NVM_DIR/*/lib/node_modules:} echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" else @@ -423,7 +423,7 @@ nvm() { echo "$VERSION version is not installed yet" return 1 fi - if [ `expr $PATH : ".*$NVM_DIR/.*/bin"` != 0 ]; then + if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin"` != 0 ]; then PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$VERSION/bin${PATH#*$NVM_DIR/*/bin} else PATH="$NVM_DIR/$VERSION/bin:$PATH" @@ -432,12 +432,12 @@ nvm() { MANPATH=$(manpath) fi MANPATH=${MANPATH#*$NVM_DIR/*/man:} - if [ `expr $MANPATH : ".*$NVM_DIR/.*/share/man"` != 0 ]; then + if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man"` != 0 ]; then MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$VERSION/share/man${MANPATH#*$NVM_DIR/*/share/man} else MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH" fi - if [ `expr $NODE_PATH : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then + if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules} else NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH" @@ -461,7 +461,7 @@ nvm() { echo "$VERSION version is not installed yet" return; fi - if [ `expr $NODE_PATH : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then + if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then RUN_NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules} else RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH" From a3331ffdb0a3630d8f5ba3efd22d49778c0b8fba Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 21 Feb 2014 20:59:50 +1000 Subject: [PATCH 07/16] fix errors due to use of unportable == operator The `==` operator is not defined by POSIX and many test(1) (also spelled `[`) implementations do not support it. Replace uses of `==` with the POSIX-conformant `=` equality operator. --- install-gitless.sh | 4 ++-- nvm.sh | 2 +- ... deactivate\" should unset the nvm environment variables." | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/install-gitless.sh b/install-gitless.sh index d2ee6e6..b5313c8 100755 --- a/install-gitless.sh +++ b/install-gitless.sh @@ -5,11 +5,11 @@ function fatalExit (){ } # an alternative URL that could be used: https://github.com/creationix/nvm/tarball/master -if [ "$NVM_SOURCE" == "" ]; then +if [ "$NVM_SOURCE" = "" ]; then NVM_SOURCE="https://raw.github.com/creationix/nvm/master/nvm.sh" fi -if [ "$NVM_DIR" == "" ]; then +if [ "$NVM_DIR" = "" ]; then NVM_DIR="$HOME/.nvm" fi diff --git a/nvm.sh b/nvm.sh index 8455c69..8df39bb 100755 --- a/nvm.sh +++ b/nvm.sh @@ -351,7 +351,7 @@ nvm() { ;; "uninstall" ) [ $# -ne 2 ] && nvm help && return - if [ $2 == `nvm_version` ]; then + if [ "$2" = `nvm_version` ]; then echo "nvm: Cannot uninstall currently-active node version, $2." return 1 fi diff --git "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." index 813f226..e112709 100755 --- "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." +++ "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." @@ -4,7 +4,7 @@ mkdir -p ../../v0.2.3 die () { echo $@ ; exit 1; } -[ `expr $PATH : ".*v0.2.3/.*/bin"` == 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 +[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 . ../../nvm.sh nvm use v0.2.3 && From 21771e7369a8eef28b6df21bf6066b4d13b9a864 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 21 Feb 2014 21:06:53 +1000 Subject: [PATCH 08/16] fix logic error in nvm deactivate test --- ...vm deactivate\" should unset the nvm environment variables." | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." index e112709..2526bdb 100755 --- "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." +++ "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." @@ -11,4 +11,4 @@ nvm use v0.2.3 && [ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] || die "Failed to activate v0.2.3" nvm deactivate && -[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] || die "Failed to deactivate v0.2.3" +[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || die "Failed to deactivate v0.2.3" From ca0c8a7f1db78a60aed6e4e6ea1119d827f8e363 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 21 Feb 2014 22:10:17 +1000 Subject: [PATCH 09/16] handle echo implementations that do not support `-e` --- nvm.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 8df39bb..cc7a7a8 100755 --- a/nvm.sh +++ b/nvm.sh @@ -26,6 +26,9 @@ 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" @@ -139,7 +142,7 @@ nvm_checksum() { } colorize_version() { - echo -e "\033[0;34m$1\033[0m" + echo $DASH_E "\033[0;34m$1\033[0m" } print_versions() { @@ -482,7 +485,7 @@ nvm() { return ;; "current" ) - echo -ne "current: \t"; nvm_version current + echo $DASH_E -n "current: \t"; nvm_version current ;; "alias" ) mkdir -p $NVM_DIR/alias From 1d6145de5a69db9c3de2974ba687469304a37517 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 21 Feb 2014 23:25:45 +1000 Subject: [PATCH 10/16] fix explicit version matching on FreeBSD FreeBSD's regular expression library does not like the pattern used for matching explicit version strings in `nvm_ls`. Change the pattern to something more specific that works on FreeBSD. --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index cc7a7a8..4f0c991 100755 --- a/nvm.sh +++ b/nvm.sh @@ -93,7 +93,7 @@ nvm_ls() { return fi # If it looks like an explicit version, don't do anything funny - if [ `expr "$PATTERN" : "v.*.\?.*.\?.*$"` != 0 ]; then + if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then VERSIONS="$PATTERN" else VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "v$PATTERN*" -exec basename '{}' ';' \ From 8cba9c57817f230351134c69c0c08ed990dfcba0 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 22 Feb 2014 00:00:10 +1000 Subject: [PATCH 11/16] avoid nullglob in alias command --- nvm.sh | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/nvm.sh b/nvm.sh index 4f0c991..75b2be6 100755 --- a/nvm.sh +++ b/nvm.sh @@ -34,16 +34,6 @@ if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist" fi -nvm_set_nullglob() { - if has "setopt"; then - # Zsh - setopt NULL_GLOB - elif has "shopt"; then - # Bash - shopt -s nullglob - fi -} - # Obtain nvm version from rc file rc_nvm_version() { if [ -e .nvmrc ]; then @@ -491,7 +481,8 @@ nvm() { mkdir -p $NVM_DIR/alias if [ $# -le 2 ]; then local DEST - for ALIAS in $(nvm_set_nullglob; echo $NVM_DIR/alias/$2* ); do + for ALIAS in $NVM_DIR/alias/$2*; do + if [ -e "$ALIAS" ]; then DEST=`cat $ALIAS` VERSION=`nvm_version $DEST` if [ "$DEST" = "$VERSION" ]; then @@ -499,6 +490,7 @@ nvm() { else echo "$(basename $ALIAS) -> $DEST (-> $VERSION)" fi + fi done return fi From e6a5374bfb74a9c70b65c40a9765275c027aafe8 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 22 Feb 2014 00:06:53 +1000 Subject: [PATCH 12/16] colorize output only if echo supports it --- nvm.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 75b2be6..18979f1 100755 --- a/nvm.sh +++ b/nvm.sh @@ -132,7 +132,11 @@ nvm_checksum() { } colorize_version() { - echo $DASH_E "\033[0;34m$1\033[0m" + if [ -n "$DASH_E" ]; then + echo $DASH_E "\033[0;34m$1\033[0m" + else + echo $1 + fi } print_versions() { From dcba51310869211eb367b8645dcdd3b4f523b818 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 22 Feb 2014 11:25:45 +1000 Subject: [PATCH 13/16] address remaining comments from #363 --- nvm.sh | 2 +- ...ing \"nvm current\" should display current nvm environment." | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 18979f1..e60c341 100755 --- a/nvm.sh +++ b/nvm.sh @@ -93,7 +93,7 @@ nvm_ls() { echo "N/A" return fi - printf "$VERSIONS\n" + echo "$VERSIONS" return } 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 40d528f..a2c93a5 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" \ No newline at end of file +[ `expr "$(nvm current)" : ".*current"` != 0 ] || die "Failed to find current version" From 3b21b76106e1b7556505dde2602b3577b0ce10eb Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 22 Feb 2014 11:58:39 +1000 Subject: [PATCH 14/16] fix install from source on FreeBSD 10 Compile with CXX=c++ on FreeBSD, as FreeBSD >= 10.0 no longer has GCC in the base system (c++ is hardlinked to clang++ on FreeBSD 10.0 and g++ on FreeBSD < 10). --- nvm.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index e60c341..c776920 100755 --- a/nvm.sh +++ b/nvm.sh @@ -304,6 +304,7 @@ nvm() { make='make' if [ "$os" = "freebsd" ]; then make='gmake' + MAKE_CXX="CXX=c++" fi local tmpdir="$NVM_DIR/src" local tmptarball="$tmpdir/node-$VERSION.tar.gz" @@ -321,9 +322,9 @@ nvm() { tar -xzf "$tmptarball" -C "$tmpdir" && \ cd "$tmpdir/node-$VERSION" && \ ./configure --prefix="$NVM_DIR/$VERSION" $ADDITIONAL_PARAMETERS && \ - $make && \ + $make $MAKE_CXX && \ rm -f "$NVM_DIR/$VERSION" 2>/dev/null && \ - $make install + $make $MAKE_CXX install ) then nvm use $VERSION From 9108a7f7fa2f03cdd22d402230091a180b652d53 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 22 Feb 2014 12:18:50 +1000 Subject: [PATCH 15/16] remove duplicate install test `test/slow/install` is identical to `test/slow/install from source` except in the version installed. Remove it. --- test/slow/install | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100755 test/slow/install diff --git a/test/slow/install b/test/slow/install deleted file mode 100755 index 460627b..0000000 --- a/test/slow/install +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -set -e -. ../../nvm.sh - -# Remove the stuff we're clobbering. -[ -e ../../v0.6.14 ] && rm -R ../../v0.6.14 - -# Install -nvm install 0.6.14 - -# Check -[ -d ../../v0.6.14 ] -nvm run v0.6.14 --version | grep v0.6.14 From 332ae1afcbaa655b3a3c78ad3cc708b2c08b5bed Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 22 Feb 2014 12:15:40 +1000 Subject: [PATCH 16/16] use a more portable release in install tests The tests for nvm install currently install v0.8.6, which doesn't build on FreeBSD due to Linuxisms. Switch to a more recent version that does work. --- test/slow/install from binary | 10 ++++++---- test/slow/install from source | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/slow/install from binary b/test/slow/install from binary index c22e0d8..a1d35bc 100755 --- a/test/slow/install from binary +++ b/test/slow/install from binary @@ -3,12 +3,14 @@ set -e . ../../nvm.sh +VERSION=v0.10.26 + # Remove the stuff we're clobbering. -[ -e ../../v0.8.6 ] && rm -R ../../v0.8.6 +[ -e ../../$VERSION ] && rm -R ../../$VERSION # Install from binary -nvm install 0.8.6 +nvm install $VERSION # Check -[ -d ../../v0.8.6 ] -nvm run v0.8.6 --version | grep v0.8.6 +[ -d ../../$VERSION ] +nvm run $VERSION --version | grep $VERSION diff --git a/test/slow/install from source b/test/slow/install from source index d124b27..d03724c 100755 --- a/test/slow/install from source +++ b/test/slow/install from source @@ -3,12 +3,14 @@ set -e . ../../nvm.sh +VERSION=v0.10.26 + # Remove the stuff we're clobbering. -[ -e ../../v0.8.6 ] && rm -R ../../v0.8.6 +[ -e ../../$VERSION ] && rm -R ../../$VERSION # Install from source -nvm install -s 0.8.6 +nvm install -s $VERSION # Check -[ -d ../../v0.8.6 ] -nvm run v0.8.6 --version | grep v0.8.6 +[ -d ../../$VERSION ] +nvm run $VERSION --version | grep $VERSION