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: diff --git a/nvm.sh b/nvm.sh index 45bf52e..b3ec60e 100755 --- a/nvm.sh +++ b/nvm.sh @@ -33,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 @@ -60,6 +71,21 @@ nvm_ls() return } +nvm_ls_remote() +{ + PATTERN=$1 + VERSIONS=`curl -s http://nodejs.org/dist/ \ + | 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 + echo "N/A" + return + fi + echo "$VERSIONS" + return +} + print_versions() { OUTPUT='' @@ -92,6 +118,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 " @@ -114,7 +141,7 @@ nvm() nvm help return fi - VERSION=`nvm_version $2` + VERSION=`nvm_remote_version $2` ADDITIONAL_PARAMETERS='' shift shift @@ -174,7 +201,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 @@ -257,6 +285,10 @@ nvm() fi return ;; + "ls-remote" | "list-remote" ) + print_versions "`nvm_ls_remote $2`" + return + ;; "alias" ) mkdir -p $NVM_DIR/alias if [ $# -le 2 ]; then