From b82bcfbd471d8ebab32d0736ca806fec1fa6bf91 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 25 Nov 2010 01:42:24 -0800 Subject: [PATCH 1/3] A package.json install that works. It's an ugly hack, but it works. --- install.sh | 24 ++++++++++++++++++++++++ package.json | 3 ++- uninstall.sh | 23 +++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 install.sh create mode 100755 uninstall.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..8ad7d20 --- /dev/null +++ b/install.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +dir=$npm_config_root/.npm/$npm_package_name/$npm_package_version/package + +# add lines to the bashrc. +has=$(cat ~/.bashrc | egrep "^# ADDED BY npm FOR NVM$" || true) +if [ "x$has" != "x" ]; then + exit 0 +fi +cat <>~/.bashrc +# ADDED BY npm FOR NVM +NVM_DIR=$dir +. \$NVM_DIR/nvm.sh +nvm use +# END ADDED BY npm FOR NVM +NVM_CODE + +cat <" +, "scripts" : + { "install" : "./install.sh" , "uninstall" : "./uninstall.sh" } } diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..a139d2c --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,23 @@ +#!/bin/bash + + +has=$(cat ~/.bashrc | egrep "^# ADDED BY npm FOR NVM$" || true) +if [ "x$has" == "x" ]; then + echo "doesn't have it, exiting" + exit 0 +fi +tmp=~/.bashrc.tmp +cat ~/.bashrc | { + incode=0 + while read line; do + if [ "$line" == "# ADDED BY npm FOR NVM" ]; then + incode=1 + elif [ "$line" == "# END ADDED BY npm FOR NVM" ] \ + && [ $incode -eq 1 ]; then + incode=0 + elif [ $incode -eq 0 ]; then + echo "$line" >> $tmp + fi + done +} +mv $tmp ~/.bashrc From 9ef89f51c998de17b43d1429eb3f13f3825611f1 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 25 Nov 2010 01:43:02 -0800 Subject: [PATCH 2/3] v0.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 024693e..4935629 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name" : "nvm" -, "version" : "0.0.2" +, "version" : "0.0.3" , "author" : "Tim Caswell " , "scripts" : { "install" : "./install.sh" , "uninstall" : "./uninstall.sh" } From dd32e5880d8a1f82c7e2d04b2fbbd650817d5cc5 Mon Sep 17 00:00:00 2001 From: Tim Caswell Date: Fri, 10 Dec 2010 11:32:16 -0800 Subject: [PATCH 3/3] Trim and update nvm --- README.markdown | 37 ++++++++++------------------ nvm.sh | 64 +++++++++++-------------------------------------- 2 files changed, 26 insertions(+), 75 deletions(-) diff --git a/README.markdown b/README.markdown index 728efb7..2abfd18 100644 --- a/README.markdown +++ b/README.markdown @@ -2,7 +2,7 @@ ## Installation -First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential package works. You'll also need `git` if you want to track HEAD. +First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential and libssl-dev packages work. To install create a folder somewhere in your filesystem with the "`nvm.sh`" file inside it. I put mine in a folder called "`.nvm`". @@ -10,38 +10,25 @@ Or if you have `git` installed, then just clone it: git clone git://github.com/creationix/nvm.git ~/.nvm -Then add two lines to your bash profile: - - NVM_DIR=$HOME/.nvm - . $NVM_DIR/nvm.sh - nvm use - -The first line loads the `nvm` function into your bash shell so that it's available as a command. The second line sets your default node version to the latest released version. +To activate nvm, you need to source it from your bash shell + . ~/.nvm/nvm.sh + ## Usage -To download, install, and use the v0.1.94 release of node do this: +To download, install, and use the v0.2.5 release of node do this: - nvm install v0.1.94 + nvm install v0.2.5 And then in any new shell just use the installed version: - nvm use v0.1.94 - -If you want to track HEAD then use the clone command: - - nvm clone - -Then in any new shell you can get this version with: - - nvm use HEAD - -When you want to grab the latest from the node repo do: - - nvm update + nvm use v0.2.5 If you want to see what versions you have installed issue: - nvm list + nvm ls + +To restore your PATH, you can deactivate it. + + nvm deactivate -If you want to install nvm to somewhere other than `$HOME/.nvm`, then set the `$NVM_DIR` environment variable before sourcing the nvm.sh file. \ No newline at end of file diff --git a/nvm.sh b/nvm.sh index d1afb84..f54cab8 100644 --- a/nvm.sh +++ b/nvm.sh @@ -5,6 +5,9 @@ # Implemented by Tim Caswell # with much bash help from Matthew Ranney +# Auto detect the NVM_DIR using magic bash 3.x stuff +export NVM_DIR=$(dirname ${BASH_ARGV[0]}) + nvm() { START=`pwd` @@ -18,18 +21,15 @@ nvm() echo "Node Version Manager" echo echo "Usage:" - echo " nvm help (Show this message)" - echo " nvm install version (Download and install a released version)" - echo " nvm list (Show all installed versions)" - echo " nvm use version (Set this version in the PATH)" - echo " nvm use (Use the latest stable version)" - echo " nvm deactivate (Remove nvm entry from PATH)" - echo " nvm addlib (Copies the module in cwd to the current env)" - echo " nvm linklib (Links the module in cwd to the current env)" - echo " nvm listlibs (Show the modules in the current env)" + echo " nvm help Show this message" + echo " nvm install Download and install a " + echo " nvm use Modify PATH to use " + echo " nvm ls List versions currently installed" + echo " nvm deactivate Undo effects of NVM on current shell" echo echo "Example:" - echo " nvm install v0.1.94" + echo " nvm install v0.2.5" + echo " nvm use v0.2.5" echo ;; "install" ) @@ -55,37 +55,11 @@ nvm() else echo "Could not find $NVM_DIR/*/bin in \$PATH" fi - unset NVM_PATH - unset NVM_DIR - unset NVM_BIN - echo "Unset NVM_PATH, NVM_BIN, and NVM_DIR." - ;; - "addlib" ) - mkdir -p $NVM_PATH - mkdir -p $NVM_BIN - if [ -d `pwd`/lib ]; then - cp -r `pwd`/lib/ "$NVM_PATH/" - cp -r `pwd`/bin/ "$NVM_BIN/" - else - echo "Can't find lib dir at `pwd`/lib" - fi - ;; - "linklib" ) - mkdir -p $NVM_PATH - mkdir -p $NVM_BIN - if [ -d `pwd`/lib ]; then - ln -sf `pwd`/lib/* "$NVM_PATH/" - ln -sf `pwd`/bin/* "$NVM_BIN/" - else - echo "Can't find lib dir at `pwd`/lib" - fi ;; "use" ) if [ $# -ne 2 ]; then - for f in $NVM_DIR/v*; do - nvm use ${f##*/} > /dev/null - done - return; + nvm help + return fi if [ ! -d $NVM_DIR/$2 ]; then echo "$2 version is not installed yet" @@ -101,21 +75,11 @@ nvm() export NVM_BIN="$NVM_DIR/$2/bin" echo "Now using node $2" ;; - "listlibs" ) - ls $NVM_PATH | grep -v wafadmin - ;; - "list" ) + "ls" ) if [ $# -ne 1 ]; then nvm help return; fi - if [ -d $NVM_DIR/HEAD ]; then - if [[ $PATH == *$NVM_DIR/HEAD/bin* ]]; then - echo "HEAD *" - else - echo "HEAD" - fi - fi for f in $NVM_DIR/v*; do if [[ $PATH == *$f/bin* ]]; then echo "v${f##*v} *" @@ -128,4 +92,4 @@ nvm() nvm help ;; esac -} \ No newline at end of file +}