diff --git a/nvm.sh b/nvm.sh index 88bf290..abf16f3 100644 --- a/nvm.sh +++ b/nvm.sh @@ -138,8 +138,8 @@ nvm_ls() { | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | grep -v '^ *\.'` fi if [ -z "$VERSIONS" ]; then - echo "N/A" - return + echo "N/A" + return fi echo "$VERSIONS" return @@ -181,7 +181,7 @@ nvm_checksum() { echo 'Checksums empty' #missing in raspberry pi binary return else - echo 'Checksums do not match.' + echo 'Checksums do not match.' >&2 return 1 fi } @@ -308,7 +308,7 @@ nvm() { fi provided_version="$NVM_RC_VERSION" fi - [ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." && return + [ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." >&2 && return VERSION=`nvm_remote_version $provided_version` ADDITIONAL_PARAMETERS='' @@ -322,13 +322,13 @@ nvm() { done if [ -d "$NVM_DIR/$VERSION" ]; then - echo "$VERSION is already installed." + echo "$VERSION is already installed." >&2 nvm use "$VERSION" return $? fi if [ "$VERSION" = "N/A" ]; then - echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." + echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." >&2 return 3 fi @@ -395,10 +395,10 @@ nvm() { if ! nvm_has "npm" ; then echo "Installing npm..." if [ "`expr "$VERSION" : '\(^v0\.1\.\)'`" != '' ]; then - echo "npm requires node v0.2.3 or higher" + echo "npm requires node v0.2.3 or higher" >&2 elif [ "`expr "$VERSION" : '\(^v0\.2\.\)'`" != '' ]; then if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then - echo "npm requires node v0.2.3 or higher" + echo "npm requires node v0.2.3 or higher" >&2 else curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh fi @@ -407,7 +407,7 @@ nvm() { fi fi else - echo "nvm: install $VERSION failed!" + echo "nvm: install $VERSION failed!" >&2 return 1 fi ;; @@ -415,12 +415,12 @@ nvm() { [ $# -ne 2 ] && nvm help && return PATTERN=`nvm_format_version $2` if [ "$PATTERN" = `nvm_version` ]; then - echo "nvm: Cannot uninstall currently-active node version, $PATTERN." + echo "nvm: Cannot uninstall currently-active node version, $PATTERN." >&2 return 1 fi VERSION=`nvm_version $PATTERN` if [ ! -d $NVM_DIR/$VERSION ]; then - echo "$VERSION version is not installed..." + echo "$VERSION version is not installed..." >&2 return; fi @@ -447,19 +447,19 @@ nvm() { hash -r echo "$NVM_DIR/*/bin removed from \$PATH" else - echo "Could not find $NVM_DIR/*/bin in \$PATH" + echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2 fi if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"` echo "$NVM_DIR/*/share/man removed from \$MANPATH" else - echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" + echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2 fi if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then export NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"` echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" else - echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" + echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" >&2 fi ;; "use" ) @@ -470,7 +470,7 @@ nvm() { if [ $# -eq 1 ]; then nvm_rc_version if [ -n "$NVM_RC_VERSION" ]; then - VERSION=`nvm_version $NVM_RC_VERSION` + VERSION=`nvm_version $NVM_RC_VERSION` fi else VERSION=`nvm_version $2` @@ -483,7 +483,7 @@ nvm() { VERSION=`nvm_version $2` fi if [ ! -d "$NVM_DIR/$VERSION" ]; then - echo "$VERSION version is not installed yet" + echo "$VERSION version is not installed yet" >&2 return 1 fi # Strip other version from PATH @@ -542,7 +542,7 @@ nvm() { fi if [ ! -d "$NVM_DIR/$VERSION" ]; then - echo "$VERSION version is not installed yet" + echo "$VERSION version is not installed yet" >&2 return; fi RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"` @@ -558,8 +558,8 @@ nvm() { return ;; "ls-remote" | "list-remote" ) - nvm_print_versions "`nvm_ls_remote $2`" - return + nvm_print_versions "`nvm_ls_remote $2`" + return ;; "current" ) nvm_version current @@ -573,18 +573,18 @@ nvm() { DEST=`cat $ALIAS` VERSION=`nvm_version $DEST` if [ "$DEST" = "$VERSION" ]; then - echo "$(basename $ALIAS) -> $DEST" + echo "$(basename $ALIAS) -> $DEST" else - echo "$(basename $ALIAS) -> $DEST (-> $VERSION)" + echo "$(basename $ALIAS) -> $DEST (-> $VERSION)" fi fi done return fi if [ -z "$3" ]; then - rm -f $NVM_DIR/alias/$2 - echo "$2 -> *poof*" - return + rm -f $NVM_DIR/alias/$2 + echo "$2 -> *poof*" + return fi mkdir -p $NVM_DIR/alias VERSION=`nvm_version $3` @@ -593,7 +593,7 @@ nvm() { fi echo $3 > "$NVM_DIR/alias/$2" if [ ! "$3" = "$VERSION" ]; then - echo "$2 -> $3 (-> $VERSION)" + echo "$2 -> $3 (-> $VERSION)" else echo "$2 -> $3" fi @@ -601,34 +601,34 @@ nvm() { "unalias" ) mkdir -p $NVM_DIR/alias [ $# -ne 2 ] && nvm help && return 127 - [ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" && return + [ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return rm -f $NVM_DIR/alias/$2 echo "Deleted alias $2" ;; "copy-packages" ) - if [ $# -ne 2 ]; then - nvm help - return 127 - fi - VERSION=`nvm_version $2` - local ROOT=`(nvm use $VERSION && npm -g root)` - local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1)) + if [ $# -ne 2 ]; then + nvm help + return 127 + fi + VERSION=`nvm_version $2` + local ROOT=`(nvm use $VERSION && npm -g root)` + local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1)) - # 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" " "` + # 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" " "` - npm install -g ${INSTALLS[@]} + npm install -g ${INSTALLS[@]} ;; "clear-cache" ) - rm -f $NVM_DIR/v* 2>/dev/null - echo "Cache cleared." + rm -f $NVM_DIR/v* 2>/dev/null + echo "Cache cleared." ;; "version" ) - nvm_version $2 + nvm_version $2 ;; "--version" ) - echo "0.7.0" + echo "0.7.0" ;; "unload" ) unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1 diff --git "a/test/fast/Running \"nvm install\" with an invalid version fails nicely" "b/test/fast/Running \"nvm install\" with an invalid version fails nicely" index 2f556e9..d113890 100755 --- "a/test/fast/Running \"nvm install\" with an invalid version fails nicely" +++ "b/test/fast/Running \"nvm install\" with an invalid version fails nicely" @@ -3,5 +3,5 @@ die () { echo $@ ; exit 1; } . ../../nvm.sh -[ "$(nvm install invalid.invalid)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" +[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" diff --git a/test/slow/nvm install/install already installed uses it b/test/slow/nvm install/install already installed uses it index 7e42c07..ffcbb02 100755 --- a/test/slow/nvm install/install already installed uses it +++ b/test/slow/nvm install/install already installed uses it @@ -4,7 +4,7 @@ die () { echo $@ ; exit 1; } . ../../../nvm.sh -[ "$(nvm install invalid.invalid)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" +[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" # Remove the stuff we're clobbering. [ -e ../../../v0.9.7 ] && rm -R ../../../v0.9.7