From b6f1c156da0a998442c1c0b638082390118085ce Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 26 Jun 2014 10:26:57 -0700 Subject: [PATCH 01/11] Use printf instead of `echo -e` Fixes #446 --- install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 4e266ab..17e1599 100755 --- a/install.sh +++ b/install.sh @@ -30,14 +30,14 @@ install_from_git() { if [ -d "$NVM_DIR/.git" ]; then echo "=> nvm is already installed in $NVM_DIR, trying to update" - echo -e "\r=> \c" + printf "\r=> " cd "$NVM_DIR" && git pull 2> /dev/null || { echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." } else # Cloning to $NVM_DIR echo "=> Downloading nvm from git to '$NVM_DIR'" - echo -e "\r=> \c" + printf "\r=> " mkdir -p "$NVM_DIR" git clone "$NVM_SOURCE" "$NVM_DIR" fi @@ -113,12 +113,12 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then fi echo " OR" echo "=> Append the following lines to the correct file yourself:" - echo -e "$SOURCE_STR" + printf "$SOURCE_STR" echo else if ! grep -qc 'nvm.sh' $PROFILE; then echo "=> Appending source string to $PROFILE" - echo -e "$SOURCE_STR" >> "$PROFILE" + printf "$SOURCE_STR" >> "$PROFILE" else echo "=> Source string already in $PROFILE" fi From bb250b573083b39b0b8bdc1ccb9f0280db0050f3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 26 Jun 2014 10:28:14 -0700 Subject: [PATCH 02/11] v0.9.0 --- README.markdown | 6 +++--- nvm.sh | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index d87f3c5..8f7afc0 100644 --- a/README.markdown +++ b/README.markdown @@ -8,11 +8,11 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w To install you could use the [install script][2] using cURL: - curl https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh + curl https://raw.githubusercontent.com/creationix/nvm/v0.9.0/install.sh | sh or Wget: - wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh + wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.9.0/install.sh | sh The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`). @@ -163,7 +163,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But nvm install -s 0.8.6 [1]: https://github.com/creationix/nvm.git -[2]: https://github.com/creationix/nvm/blob/v0.8.0/install.sh +[2]: https://github.com/creationix/nvm/blob/v0.9.0/install.sh [3]: https://travis-ci.org/creationix/nvm [Urchin]: https://github.com/scraperwiki/urchin diff --git a/nvm.sh b/nvm.sh index b54ce38..54a25f6 100644 --- a/nvm.sh +++ b/nvm.sh @@ -650,7 +650,7 @@ nvm() { nvm_version $2 ;; "--version" ) - echo "0.8.0" + echo "0.9.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/package.json b/package.json index 3da7af8..7c5d847 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nvm", - "version": "0.8.0", + "version": "0.9.0", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "directories": { "test": "test" From 8349f0ff4872d71b52bc52c8a8b32596ee23202b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 22 Jun 2014 11:33:26 -0700 Subject: [PATCH 03/11] Make sure `nvm ls foo` returns a nonzero exit code when a version is not found. Fixes #440. --- nvm.sh | 6 ++++-- ...foo\" should return a nonzero exit code when not found" | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100755 "test/fast/Running \"nvm ls foo\" should return a nonzero exit code when not found" diff --git a/nvm.sh b/nvm.sh index 54a25f6..6354034 100644 --- a/nvm.sh +++ b/nvm.sh @@ -571,11 +571,13 @@ nvm() { NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" ;; "ls" | "list" ) - nvm_print_versions "`nvm_ls $2`" + NVM_LS_OUTPUT=$(nvm_ls "$2") + NVM_LS_EXIT_CODE=$? + nvm_print_versions "$NVM_LS_OUTPUT" if [ $# -eq 1 ]; then nvm alias fi - return + return $NVM_LS_EXIT_CODE && $? ;; "ls-remote" | "list-remote" ) nvm_print_versions "`nvm_ls_remote $2`" diff --git "a/test/fast/Running \"nvm ls foo\" should return a nonzero exit code when not found" "b/test/fast/Running \"nvm ls foo\" should return a nonzero exit code when not found" new file mode 100755 index 0000000..b29a947 --- /dev/null +++ "b/test/fast/Running \"nvm ls foo\" should return a nonzero exit code when not found" @@ -0,0 +1,7 @@ + #!/bin/sh + +. ../../nvm.sh + +nvm ls nonexistent_version +[ "$?" = "3" ] + From 4b593bcda23314260880a1793e21c40b93908b5c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 22 Jun 2014 17:20:31 -0700 Subject: [PATCH 04/11] Make sure these vars are local, where supported --- nvm.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nvm.sh b/nvm.sh index 6354034..20c781a 100644 --- a/nvm.sh +++ b/nvm.sh @@ -571,6 +571,8 @@ nvm() { NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" ;; "ls" | "list" ) + local NVM_LS_OUTPUT + local NVM_LS_EXIT_CODE NVM_LS_OUTPUT=$(nvm_ls "$2") NVM_LS_EXIT_CODE=$? nvm_print_versions "$NVM_LS_OUTPUT" From fb215546ee5041b4146c1d0806a0390a759845c5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 26 Jun 2014 16:52:48 -0700 Subject: [PATCH 05/11] Don't bother trying to return the exit code of `nvm alias` or `nvm_print_versions` --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 20c781a..782a432 100644 --- a/nvm.sh +++ b/nvm.sh @@ -579,7 +579,7 @@ nvm() { if [ $# -eq 1 ]; then nvm alias fi - return $NVM_LS_EXIT_CODE && $? + return $NVM_LS_EXIT_CODE ;; "ls-remote" | "list-remote" ) nvm_print_versions "`nvm_ls_remote $2`" From 3e5037a1bed2056ba633e1198a07d70c2f5fc038 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 26 Jun 2014 17:06:45 -0700 Subject: [PATCH 06/11] v0.10.0 --- README.markdown | 6 +++--- nvm.sh | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 8f7afc0..1bf93a8 100644 --- a/README.markdown +++ b/README.markdown @@ -8,11 +8,11 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w To install you could use the [install script][2] using cURL: - curl https://raw.githubusercontent.com/creationix/nvm/v0.9.0/install.sh | sh + curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | sh or Wget: - wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.9.0/install.sh | sh + wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | sh The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`). @@ -163,7 +163,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But nvm install -s 0.8.6 [1]: https://github.com/creationix/nvm.git -[2]: https://github.com/creationix/nvm/blob/v0.9.0/install.sh +[2]: https://github.com/creationix/nvm/blob/v0.10.0/install.sh [3]: https://travis-ci.org/creationix/nvm [Urchin]: https://github.com/scraperwiki/urchin diff --git a/nvm.sh b/nvm.sh index 782a432..cb4e180 100644 --- a/nvm.sh +++ b/nvm.sh @@ -654,7 +654,7 @@ nvm() { nvm_version $2 ;; "--version" ) - echo "0.9.0" + echo "0.10.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/package.json b/package.json index 7c5d847..0c95864 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nvm", - "version": "0.9.0", + "version": "0.10.0", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "directories": { "test": "test" From fb5a51b1b7f953971d5a0cc5e610587f34a9b1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski?= Date: Wed, 2 Jul 2014 14:58:56 +0200 Subject: [PATCH 07/11] Use bash, not sh for install scritps Install scripts don't work in pure sh; they may work on some systems where the /bin/sh binary actually implements more than the pure Bourne Shell but fail on other ones (e.g. Ubuntu). Just using bash works. --- README.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 1bf93a8..d4b40ef 100644 --- a/README.markdown +++ b/README.markdown @@ -8,11 +8,11 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w To install you could use the [install script][2] using cURL: - curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | sh + curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash or Wget: - wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | sh + wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`). From f214ffaf1fbd18604db1dda7f024359e30e6d93b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 5 Jul 2014 11:05:15 -0700 Subject: [PATCH 08/11] Oxford comma --- README.markdown | 2 +- install.sh | 4 ++-- nvm.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index d4b40ef..11cb9e9 100644 --- a/README.markdown +++ b/README.markdown @@ -18,7 +18,7 @@ or Wget: You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install. -*NB. The installer can use Git, cURL or Wget to download NVM, whatever is available.* +*NB. The installer can use Git, curl, or wget to download NVM, whatever is available.* ### Manual install diff --git a/install.sh b/install.sh index 17e1599..b67c5e7 100755 --- a/install.sh +++ b/install.sh @@ -68,7 +68,7 @@ if [ -z "$METHOD" ]; then elif has "curl"; then install_as_script else - echo >&2 "You need git, curl or wget to install nvm" + echo >&2 "You need git, curl, or wget to install nvm" exit 1 fi else @@ -105,7 +105,7 @@ SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then if [ -z $PROFILE ]; then - echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile." + echo "=> Profile not found. Tried ~/.bash_profile, ~/.zshrc, and ~/.profile." echo "=> Create one of them and run this script again" else echo "=> Profile $PROFILE not found" diff --git a/nvm.sh b/nvm.sh index cb4e180..6b94dda 100644 --- a/nvm.sh +++ b/nvm.sh @@ -274,7 +274,7 @@ nvm() { echo " nvm alias default 0.10.24 Set default node version on a shell" echo echo "Note:" - echo " to remove, delete or uninstall nvm - just remove ~/.nvm, ~/.npm and ~/.bower folders" + echo " to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders" echo ;; From 7e269961c3fdfa9b0c592efccd80a4476e4c0f88 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 5 Jul 2014 13:42:44 -0700 Subject: [PATCH 09/11] In `install.sh`, rename `has` to `nvm_has` for consistency with `nvm.sh`. --- install.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index b67c5e7..519d7d6 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,7 @@ set -e -has() { +nvm_has() { type "$1" > /dev/null 2>&1 return $? } @@ -11,8 +11,8 @@ if [ -z "$NVM_DIR" ]; then NVM_DIR="$HOME/.nvm" fi -if ! has "curl"; then - if has "wget"; then +if ! nvm_has "curl"; then + if nvm_has "wget"; then # Emulate curl with wget curl() { ARGS="$* " @@ -63,9 +63,9 @@ install_as_script() { if [ -z "$METHOD" ]; then # Autodetect install method - if has "git"; then + if nvm_has "git"; then install_from_git - elif has "curl"; then + elif nvm_has "curl"; then install_as_script else echo >&2 "You need git, curl, or wget to install nvm" @@ -73,14 +73,14 @@ if [ -z "$METHOD" ]; then fi else if [ "$METHOD" = "git" ]; then - if ! has "git"; then + if ! nvm_has "git"; then echo >&2 "You need git to install nvm" exit 1 fi install_from_git fi if [ "$METHOD" = "script" ]; then - if ! has "curl"; then + if ! nvm_has "curl"; then echo >&2 "You need curl or wget to install nvm" exit 1 fi From cce5df35bad1aef91ff92465e847cce04dbc4dc0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 5 Jul 2014 13:44:00 -0700 Subject: [PATCH 10/11] Naming `install.sh` functions more explicitly as being for `nvm`. --- install.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 519d7d6..94ce2ee 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ if ! nvm_has "curl"; then fi fi -install_from_git() { +install_nvm_from_git() { if [ -z "$NVM_SOURCE" ]; then NVM_SOURCE="https://github.com/creationix/nvm.git" fi @@ -43,7 +43,7 @@ install_from_git() { fi } -install_as_script() { +install_nvm_as_script() { if [ -z "$NVM_SOURCE" ]; then NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/master/nvm.sh" fi @@ -64,9 +64,9 @@ install_as_script() { if [ -z "$METHOD" ]; then # Autodetect install method if nvm_has "git"; then - install_from_git + install_nvm_from_git elif nvm_has "curl"; then - install_as_script + install_nvm_as_script else echo >&2 "You need git, curl, or wget to install nvm" exit 1 @@ -77,14 +77,14 @@ else echo >&2 "You need git to install nvm" exit 1 fi - install_from_git + install_nvm_from_git fi if [ "$METHOD" = "script" ]; then if ! nvm_has "curl"; then echo >&2 "You need curl or wget to install nvm" exit 1 fi - install_as_script + install_nvm_as_script fi fi From e0537ce3dfba5c5bcfc78f5ba29c759de9e397ad Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 5 Jul 2014 13:47:22 -0700 Subject: [PATCH 11/11] Shellcheck recommendations. --- install.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 94ce2ee..cb3d99d 100755 --- a/install.sh +++ b/install.sh @@ -18,7 +18,7 @@ if ! nvm_has "curl"; then ARGS="$* " ARGS=${ARGS/-s /-q } ARGS=${ARGS/-o /-O } - wget $ARGS + wget "$ARGS" } fi fi @@ -31,9 +31,9 @@ install_nvm_from_git() { if [ -d "$NVM_DIR/.git" ]; then echo "=> nvm is already installed in $NVM_DIR, trying to update" printf "\r=> " - cd "$NVM_DIR" && git pull 2> /dev/null || { + cd "$NVM_DIR" && (git pull 2> /dev/null || { echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." - } + }) else # Cloning to $NVM_DIR echo "=> Downloading nvm from git to '$NVM_DIR'" @@ -104,7 +104,7 @@ fi SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm" if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then - if [ -z $PROFILE ]; then + if [ -z "$PROFILE" ]; then echo "=> Profile not found. Tried ~/.bash_profile, ~/.zshrc, and ~/.profile." echo "=> Create one of them and run this script again" else @@ -113,16 +113,15 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then fi echo " OR" echo "=> Append the following lines to the correct file yourself:" - printf "$SOURCE_STR" + printf "%s" "$SOURCE_STR" echo else - if ! grep -qc 'nvm.sh' $PROFILE; then + if ! grep -qc 'nvm.sh' "$PROFILE"; then echo "=> Appending source string to $PROFILE" - printf "$SOURCE_STR" >> "$PROFILE" + printf "%s" "$SOURCE_STR" >> "$PROFILE" else echo "=> Source string already in $PROFILE" fi fi echo "=> Close and reopen your terminal to start using nvm" -