From a107b12d2ab3484f353e7f8f079a54fcf9ee3d8a Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 09:28:32 -0700 Subject: [PATCH 1/9] add /.nvm to NVM_DIR so we dont clutter up home directories --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 45bf52e..a27e6c9 100755 --- a/nvm.sh +++ b/nvm.sh @@ -7,7 +7,7 @@ # Auto detect the NVM_DIR if [ ! -d "$NVM_DIR" ]; then - export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd) + export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd)'/.nvm' fi # Make zsh glob matching behave same as bash From 07aaa91c9b2ca6d97380455ec8c96a32f3a0e353 Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 09:29:05 -0700 Subject: [PATCH 2/9] Revert "add /.nvm to NVM_DIR so we dont clutter up home directories" This reverts commit a107b12d2ab3484f353e7f8f079a54fcf9ee3d8a. --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index a27e6c9..45bf52e 100755 --- a/nvm.sh +++ b/nvm.sh @@ -7,7 +7,7 @@ # Auto detect the NVM_DIR if [ ! -d "$NVM_DIR" ]; then - export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd)'/.nvm' + export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd) fi # Make zsh glob matching behave same as bash From ebff66649e816414b4a7aacf85c16aa3cc2e673c Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 09:36:39 -0700 Subject: [PATCH 3/9] add v to version if user does not specify it to simplify commands --- nvm.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nvm.sh b/nvm.sh index 45bf52e..aab76d5 100755 --- a/nvm.sh +++ b/nvm.sh @@ -23,6 +23,10 @@ nvm_version() # The default version is the current one if [ ! "$PATTERN" ]; then PATTERN='current' + elif [ "${PATTERN:0:1}" != "v" ]; then + if [ "$PATTERN" != "default" -a "$PATTERN" != "current" ]; then + PATTERN=v$PATTERN + fi fi VERSION=`nvm_ls $PATTERN | tail -n1` From 5af8cec6dcc885ebc78d9b6727dd88ab9afc3e94 Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 09:37:12 -0700 Subject: [PATCH 4/9] updated readme --- README.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 4b07b4d..938e425 100644 --- a/README.markdown +++ b/README.markdown @@ -21,16 +21,16 @@ Often I also put in a line to use a specific version of node. To download, compile, and install the v0.6.14 release of node, do this: - nvm install v0.6.14 + nvm install 0.6.14 And then in any new shell just use the installed version: - nvm use v0.6.14 + nvm use 0.6.14 Or you can just run it: - nvm run v0.6.14 + nvm run 0.6.14 If you want to see what versions are available: From 6505c98461c7b87a8f9747d67add161bc5a1dbf2 Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 09:38:51 -0700 Subject: [PATCH 5/9] add ls-remote --- nvm.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nvm.sh b/nvm.sh index aab76d5..00aaddb 100755 --- a/nvm.sh +++ b/nvm.sh @@ -77,6 +77,17 @@ print_versions() echo -e "$OUTPUT" | column } +nvm_ls_remote() +{ + PATTERN=$1 + curl -s http://nodejs.org/dist/ \ + | egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \ + | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \ + | tr "\n" "\t" + echo "" +} + + nvm() { if [ $# -lt 1 ]; then @@ -96,6 +107,7 @@ nvm() echo " nvm run [] Run with as arguments" echo " nvm ls List installed versions" echo " nvm ls List versions matching a given description" + echo " nvm ls-remote List remote versions available for install" echo " nvm deactivate Undo effects of NVM on current shell" echo " nvm alias [] Show all aliases beginning with " echo " nvm alias Set an alias named pointing to " From 3d65d55b5a3d25cde33825f0fa5fda143aff95ce Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 09:40:00 -0700 Subject: [PATCH 6/9] install requested version automatically if it isnt available --- nvm.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 00aaddb..3b491cb 100755 --- a/nvm.sh +++ b/nvm.sh @@ -190,7 +190,8 @@ nvm() fi VERSION=`nvm_version $2` if [ ! -d $NVM_DIR/$VERSION ]; then - echo "$VERSION version is not installed yet" + echo "$VERSION version is not installed yet... installing" + nvm install $VERSION return; fi From e755c47d5a33d921cb50646d22afaeaacde4f3f2 Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 09:41:32 -0700 Subject: [PATCH 7/9] made ls-remote actually usable --- nvm.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nvm.sh b/nvm.sh index 3b491cb..c4315f6 100755 --- a/nvm.sh +++ b/nvm.sh @@ -274,6 +274,10 @@ nvm() fi return ;; + "ls-remote" | "list-remote" ) + nvm_ls_remote + return + ;; "alias" ) mkdir -p $NVM_DIR/alias if [ $# -le 2 ]; then From 693abf3173dfd2a4897b83a4c95bcde66dd1fb6f Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 10:32:36 -0700 Subject: [PATCH 8/9] make install use a different nvm_version to make not specifying the v avoid clobbering aliases --- nvm.sh | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/nvm.sh b/nvm.sh index c4315f6..8822c02 100755 --- a/nvm.sh +++ b/nvm.sh @@ -23,10 +23,6 @@ nvm_version() # The default version is the current one if [ ! "$PATTERN" ]; then PATTERN='current' - elif [ "${PATTERN:0:1}" != "v" ]; then - if [ "$PATTERN" != "default" -a "$PATTERN" != "current" ]; then - PATTERN=v$PATTERN - fi fi VERSION=`nvm_ls $PATTERN | tail -n1` @@ -37,6 +33,17 @@ nvm_version() fi } +nvm_remote_version() +{ + PATTERN=$1 + VERSION=`nvm_ls_remote $PATTERN | tail -n1` + echo "v$VERSION" + + if [ "$VERSION" = 'N/A' ]; then + return + fi +} + nvm_ls() { PATTERN=$1 @@ -64,6 +71,21 @@ nvm_ls() return } +nvm_ls_remote() +{ + PATTERN=$1 + VERSIONS=`curl -s http://nodejs.org/dist/ \ + | egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \ + | grep -w "${PATTERN}" \ + | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n` + if [ ! "$VERSIONS" ]; then + echo "N/A" + return + fi + echo "$VERSIONS" + return +} + print_versions() { OUTPUT='' @@ -77,17 +99,6 @@ print_versions() echo -e "$OUTPUT" | column } -nvm_ls_remote() -{ - PATTERN=$1 - curl -s http://nodejs.org/dist/ \ - | egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \ - | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \ - | tr "\n" "\t" - echo "" -} - - nvm() { if [ $# -lt 1 ]; then @@ -130,7 +141,7 @@ nvm() nvm help return fi - VERSION=`nvm_version $2` + VERSION=`nvm_remote_version $2` ADDITIONAL_PARAMETERS='' shift shift @@ -275,7 +286,7 @@ nvm() return ;; "ls-remote" | "list-remote" ) - nvm_ls_remote + print_versions "`nvm_ls_remote $2`" return ;; "alias" ) From 9fb65cbf7b5d191086a886b27c3d5166e0536841 Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Thu, 4 Oct 2012 11:10:31 -0700 Subject: [PATCH 9/9] add v back to ls-remote results --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 8822c02..b3ec60e 100755 --- a/nvm.sh +++ b/nvm.sh @@ -75,7 +75,7 @@ nvm_ls_remote() { PATTERN=$1 VERSIONS=`curl -s http://nodejs.org/dist/ \ - | egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \ + | egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \ | grep -w "${PATTERN}" \ | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n` if [ ! "$VERSIONS" ]; then