Add per/version NODE_PATH and a deactivate command to return everything back to normal.

master
Tim Caswell 2010-04-20 18:51:07 -05:00
parent 54495e56ae
commit 93e28c3b2f
1 changed files with 12 additions and 0 deletions

12
nvm.sh
View File

@ -24,6 +24,7 @@ nvm()
echo " nvm update (Pull and rebuild HEAD version)" echo " nvm update (Pull and rebuild HEAD version)"
echo " nvm list (Show all installed versions)" echo " nvm list (Show all installed versions)"
echo " nvm use version (Set this version in the PATH)" echo " nvm use version (Set this version in the PATH)"
echo " nvm deactivate (Remove nvm entry from PATH)"
echo echo
echo "Example:" echo "Example:"
echo " nvm install v0.1.91" echo " nvm install v0.1.91"
@ -73,6 +74,15 @@ nvm()
nvm use $2 nvm use $2
cd $START cd $START
;; ;;
"deactivate" )
if [[ $PATH == *$NVM_DIR/*/bin* ]]; then
export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:}
unset NODE_PATH
echo "$NVM_DIR/*/bin removed from \$PATH"
else
echo "Could not find $NVM_DIR/*/bin in \$PATH"
fi
;;
"use" ) "use" )
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
nvm help nvm help
@ -88,6 +98,8 @@ nvm()
PATH="$NVM_DIR/$2/bin:$PATH" PATH="$NVM_DIR/$2/bin:$PATH"
fi fi
export PATH export PATH
mkdir -p "$NVM_DIR/libs/$2"
export NODE_PATH="$NVM_DIR/libs/$2"
echo "Now using node $2" echo "Now using node $2"
;; ;;
"list" ) "list" )