Compare commits

...

21 Commits

Author SHA1 Message Date
Tim Caswell
83520186d8 Bump version 2011-02-25 12:33:32 -08:00
Tim Caswell
37ffd82af4 Update readme and comment 2011-02-25 11:53:38 -08:00
Isaac Wolkerstorfer
2d4c9b0846 Merge remote-tracking branch 'origin/master'
Conflicts:
	nvm.sh
2011-02-25 20:30:08 +01:00
Isaac Wolkerstorfer
f50e7b1d05 Merge branch 'versions' 2011-02-25 20:14:47 +01:00
Tim Caswell
66a9f01a0e Fix for ZSH by wavded 2011-02-25 09:17:27 -08:00
Tim Caswell
f668d354a9 Update the sample text to reflect current stable 2011-02-18 09:46:47 -08:00
Scott Bronson
d13d6b199a use a subshell instead of setting the START var
also don't try to install npm if node installation fails.
2011-02-13 21:33:28 -08:00
Isaac Wolkerstorfer
cd3304548f Fix some syntax issues 2011-01-29 16:24:42 +01:00
Isaac Wolkerstorfer
45b89ab396 Create alias dir on demand 2011-01-25 20:18:07 +01:00
Isaac Wolkerstorfer
57d62762e1 Don't overwrite existing NVM_DIR vars 2011-01-25 17:29:49 +01:00
Isaac Wolkerstorfer
8ec6fb22fd Create alias dir on demand 2011-01-25 17:12:13 +01:00
Isaac Wolkerstorfer
3d0082fa60 Suppress unnecessary output 2011-01-24 17:11:46 +01:00
Isaac Wolkerstorfer
85566c9682 Merge curl/wget and version changes 2011-01-22 21:52:27 +01:00
Isaac Wolkerstorfer
c060a287d0 Use curl or wget, whichever is available
Also spit out an error message if we have neither.
2011-01-22 21:07:27 +01:00
Isaac Wolkerstorfer
590b283e65 Change version() to nvm_version()
It's a bit less conflict-y
2011-01-22 20:54:15 +01:00
Isaac Wolkerstorfer
a7328b3711 Add output to sync if stable/latest changes 2011-01-22 19:31:20 +01:00
Isaac Wolkerstorfer
861766372d Add a special "default" alias
If you set a "default" alias, it will automatically be loaded when you
start a new shell.
2011-01-22 19:16:24 +01:00
Isaac Wolkerstorfer
f10ac8e8c3 Fix README for ls command 2011-01-22 19:13:02 +01:00
Isaac Wolkerstorfer
a77c632e2a Add aliases to versions
Aliases are stored as plaintext files in the $NVM_DIR/alias dir.
They may store either an explicit version (v0.3.6) or an implied version
("latest"). The latter is a "moving target", and thus possibly
dangerous, but can be useful, too.
2011-01-22 19:12:13 +01:00
Isaac Wolkerstorfer
0f6680e8b7 Use version descriptors for 'install' and 'use'
Allows things like "nvm install latest" or "nvm use stable" or "nvm use 0.2"
2011-01-22 17:57:08 +01:00
Isaac Wolkerstorfer
b2c6be9e08 Show all available versions in ls
Adds a cache of all versions available on nodejs.org using simple empty files as placeholders. When a new version is installed, it will replace the placeholder with a directory.

This makes it easier for users to see what versions are available for install, and what the latest and stable versions are.
2011-01-22 17:48:57 +01:00
5 changed files with 182 additions and 46 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
HEAD
src
v*
alias

View File

@@ -1,2 +1,3 @@
src
v*
alias

View File

@@ -19,15 +19,15 @@ Often I also put in a line to use a specific version of node.
## Usage
To download, compile, and install the v0.2.5 release of node, do this:
To download, compile, and install the v0.4.1 release of node, do this:
nvm install v0.2.5
nvm install v0.4.1
And then in any new shell just use the installed version:
nvm use v0.2.5
nvm use v0.4.1
If you want to see what versions you have installed issue:
If you want to see what versions are available:
nvm ls
@@ -35,3 +35,7 @@ To restore your PATH, you can deactivate it.
nvm deactivate
To set a default Node version to be used in any new shell, use the alias 'default':
nvm alias default v0.4.1

212
nvm.sh
View File

@@ -5,8 +5,68 @@
# Implemented by Tim Caswell <tim@creationix.com>
# 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]})
# Auto detect the NVM_DIR
if [ ! -d "$NVM_DIR" ]; then
export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}); pwd)
fi
# Emulate curl with wget, if necessary
if [ ! `which curl` ]; then
if [ `which wget` ]; then
curl() {
ARGS="$* "
ARGS=${ARGS/-s /-q }
ARGS=${ARGS/-\# /}
ARGS=${ARGS/-C - /-c }
ARGS=${ARGS/-o /-O }
wget $ARGS
}
else
NOCURL='nocurl'
curl() { echo 'Need curl or wget to proceed.' >&2; }
fi
fi
# Expand a version using the version cache
nvm_version()
{
PATTERN=$1
VERSION=''
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
nvm_version `cat $NVM_DIR/alias/$PATTERN`
return
fi
# If it looks like an explicit version, don't do anything funny
if [[ "$PATTERN" == v*.*.* ]]; then
VERSION="$PATTERN"
fi
# The default version is the current one
if [ ! "$PATTERN" -o "$PATTERN" = 'current' ]; then
VERSION=`node -v 2>/dev/null`
fi
if [ "$PATTERN" = 'stable' ]; then
PATTERN='*.*[02468].'
fi
if [ "$PATTERN" = 'latest' ]; then
PATTERN='*.*.'
fi
if [ "$PATTERN" = 'all' ]; then
(cd $NVM_DIR; ls -dG v* 2>/dev/null || echo "N/A")
return
fi
if [ ! "$VERSION" ]; then
VERSION=`(cd $NVM_DIR; ls -d v${PATTERN}* 2>/dev/null) | sort -t. -k 2,1n -k 2,2n -k 3,3n | tail -n1`
fi
if [ ! "$VERSION" ]; then
echo "N/A"
return 13
elif [ -e "$NVM_DIR/$VERSION" ]; then
(cd $NVM_DIR; ls -dG "$VERSION")
else
echo "$VERSION"
fi
}
nvm()
{
@@ -20,37 +80,51 @@ nvm()
echo "Node Version Manager"
echo
echo "Usage:"
echo " nvm help Show this message"
echo " nvm install <version> Download and install a <version>"
echo " nvm use <version> Modify PATH to use <version>"
echo " nvm ls List versions currently installed"
echo " nvm deactivate Undo effects of NVM on current shell"
echo " nvm help Show this message"
echo " nvm install <version> Download and install a <version>"
echo " nvm use <version> Modify PATH to use <version>"
echo " nvm ls List versions (installed versions are blue)"
echo " nvm ls <version> List versions matching a given description"
echo " nvm deactivate Undo effects of NVM on current shell"
echo " nvm sync Update the local cache of available versions"
echo " nvm alias [<pattern>] Show all aliases beginning with <pattern>"
echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>"
echo
echo "Example:"
echo " nvm install v0.2.5"
echo " nvm use v0.2.5"
echo " nvm install v0.4.0 Install a specific version number"
echo " nvm use stable Use the stable release"
echo " nvm install latest Install the latest, possibly unstable version"
echo " nvm use 0.2 Use the latest available 0.2.x release"
echo " nvm alias default v0.4.0 Set v0.4.0 as the default"
echo
;;
"install" )
if [ $# -ne 2 ]; then
nvm help
return;
return
fi
START=`pwd`
mkdir -p "$NVM_DIR/src" && \
cd "$NVM_DIR/src" && \
wget "http://nodejs.org/dist/node-$2.tar.gz" -N && \
tar -xzf "node-$2.tar.gz" && \
cd "node-$2" && \
./configure --prefix="$NVM_DIR/$2" && \
make && \
make install && \
nvm use $2
if ! which npm ; then
echo "Installing npm..."
curl http://npmjs.org/install.sh | sh
[ "$NOCURL" ] && curl && return
VERSION=`nvm_version $2`
if (
mkdir -p "$NVM_DIR/src" && \
cd "$NVM_DIR/src" && \
curl -C - -# "http://nodejs.org/dist/node-$VERSION.tar.gz" -o "node-$VERSION.tar.gz" && \
tar -xzf "node-$VERSION.tar.gz" && \
cd "node-$VERSION" && \
./configure --prefix="$NVM_DIR/$VERSION" && \
make && \
rm -f "$NVM_DIR/$VERSION" 2>/dev/null && \
make install
)
then
nvm use $VERSION
if ! which npm ; then
echo "Installing npm..."
curl http://npmjs.org/install.sh | sh
fi
else
echo "nvm: install $VERSION failed!"
fi
cd $START
;;
"deactivate" )
if [[ $PATH == *$NVM_DIR/*/bin* ]]; then
@@ -71,41 +145,97 @@ nvm()
nvm help
return
fi
if [ ! -d $NVM_DIR/$2 ]; then
echo "$2 version is not installed yet"
VERSION=`nvm_version $2`
if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed yet"
return;
fi
if [[ $PATH == *$NVM_DIR/*/bin* ]]; then
PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$2/bin${PATH#*$NVM_DIR/*/bin}
PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$VERSION/bin${PATH#*$NVM_DIR/*/bin}
else
PATH="$NVM_DIR/$2/bin:$PATH"
PATH="$NVM_DIR/$VERSION/bin:$PATH"
fi
if [[ $MANPATH == *$NVM_DIR/*/share/man* ]]; then
MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$2/share/man${MANPATH#*$NVM_DIR/*/share/man}
MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$VERSION/share/man${MANPATH#*$NVM_DIR/*/share/man}
else
MANPATH="$NVM_DIR/$2/share/man:$MANPATH"
MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH"
fi
export PATH
export MANPATH
export NVM_PATH="$NVM_DIR/$2/lib/node"
export NVM_BIN="$NVM_DIR/$2/bin"
echo "Now using node $2"
export NVM_PATH="$NVM_DIR/$VERSION/lib/node"
export NVM_BIN="$NVM_DIR/$VERSION/bin"
echo "Now using node $VERSION"
;;
"ls" )
if [ $# -ne 1 ]; then
nvm help
return;
nvm_version $2
return
fi
for f in $NVM_DIR/v*; do
if [[ $PATH == *$f/bin* ]]; then
echo "v${f##*v} *"
else
echo "v${f##*v}"
fi
nvm_version all
for P in {stable,latest,current}; do
echo -ne "$P: \t"; nvm_version $P
done
nvm alias
echo "# use 'nvm sync' to update from nodejs.org"
;;
"alias" )
mkdir -p $NVM_DIR/alias
if [ $# -le 2 ]; then
(cd $NVM_DIR/alias && for ALIAS in `ls $2* 2>/dev/null`; do
DEST=`cat $ALIAS`
VERSION=`nvm_version $DEST`
if [ "$DEST" = "$VERSION" ]; then
echo "$ALIAS -> $DEST"
else
echo "$ALIAS -> $DEST (-> $VERSION)"
fi
done)
return
fi
if [ ! "$3" ]; then
rm -f $NVM_DIR/alias/$2
echo "$2 -> *poof*"
return
fi
mkdir -p $NVM_DIR/alias
VERSION=`nvm_version $3`
if [ $? -ne 0 ]; then
echo "! WARNING: Version '$3' does not exist." >&2
fi
echo $3 > "$NVM_DIR/alias/$2"
if [ ! "$3" = "$VERSION" ]; then
echo "$2 -> $3 (-> $VERSION)"
echo "! WARNING: Moving target. Aliases to implicit versions may change without warning."
else
echo "$2 -> $3"
fi
;;
"sync" )
[ "$NOCURL" ] && curl && return
LATEST=`nvm_version latest`
STABLE=`nvm_version stable`
(cd $NVM_DIR
rm -f v* 2>/dev/null
printf "# syncing with nodejs.org..."
for VER in `curl -s http://nodejs.org/dist/ -o - | grep 'node-v.*\.tar\.gz' | sed -e 's/.*node-//' -e 's/\.tar\.gz.*//'`; do
touch $VER
done
echo " done."
)
[ "$STABLE" = `nvm_version stable` ] || echo "NEW stable: `nvm_version stable`"
[ "$LATEST" = `nvm_version latest` ] || echo "NEW latest: `nvm_version latest`"
;;
"clear-cache" )
rm -f $NVM_DIR/v* 2>/dev/null
echo "Cache cleared."
;;
"version" )
nvm_version $2
;;
* )
nvm help
;;
esac
}
nvm ls default >/dev/null 2>&1 && nvm use default >/dev/null

View File

@@ -1,5 +1,5 @@
{ "name" : "nvm"
, "version" : "0.0.6"
, "version" : "0.1.0"
, "author" : "Tim Caswell <tim@creationix.org>"
, "scripts" :
{ "install" : "./install.sh" , "uninstall" : "./uninstall.sh" }