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.master
parent
0f6680e8b7
commit
a77c632e2a
|
@ -1,3 +1,4 @@
|
||||||
HEAD
|
HEAD
|
||||||
src
|
src
|
||||||
v*
|
v*
|
||||||
|
alias
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
src
|
src
|
||||||
v*
|
v*
|
||||||
|
alias
|
||||||
|
|
78
nvm.sh
78
nvm.sh
|
@ -13,21 +13,25 @@ version()
|
||||||
{
|
{
|
||||||
PATTERN=$1
|
PATTERN=$1
|
||||||
VERSION=''
|
VERSION=''
|
||||||
|
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
|
||||||
|
version `cat $NVM_DIR/alias/$PATTERN`
|
||||||
|
return
|
||||||
|
fi
|
||||||
# If it looks like an explicit version, don't do anything funny
|
# If it looks like an explicit version, don't do anything funny
|
||||||
if [[ $PATTERN == v*.*.* ]]; then
|
if [[ "$PATTERN" == v*.*.* ]]; then
|
||||||
VERSION=$PATTERN
|
VERSION="$PATTERN"
|
||||||
fi
|
fi
|
||||||
# The default version is the current one
|
# The default version is the current one
|
||||||
if [ ! $PATTERN -o $PATTERN = 'current' ]; then
|
if [ ! "$PATTERN" -o "$PATTERN" = 'current' ]; then
|
||||||
VERSION=`node -v 2>/dev/null`
|
VERSION=`node -v 2>/dev/null`
|
||||||
fi
|
fi
|
||||||
if [ $PATTERN = 'stable' ]; then
|
if [ "$PATTERN" = 'stable' ]; then
|
||||||
PATTERN='*.*[02468].'
|
PATTERN='*.*[02468].'
|
||||||
fi
|
fi
|
||||||
if [ $PATTERN = 'latest' ]; then
|
if [ "$PATTERN" = 'latest' ]; then
|
||||||
PATTERN='*.*.'
|
PATTERN='*.*.'
|
||||||
fi
|
fi
|
||||||
if [ $PATTERN = 'all' ]; then
|
if [ "$PATTERN" = 'all' ]; then
|
||||||
(cd $NVM_DIR; ls -dG v* 2>/dev/null || echo "N/A")
|
(cd $NVM_DIR; ls -dG v* 2>/dev/null || echo "N/A")
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -36,8 +40,9 @@ version()
|
||||||
fi
|
fi
|
||||||
if [ ! "$VERSION" ]; then
|
if [ ! "$VERSION" ]; then
|
||||||
echo "N/A"
|
echo "N/A"
|
||||||
|
return -1
|
||||||
elif [ -e "$NVM_DIR/$VERSION" ]; then
|
elif [ -e "$NVM_DIR/$VERSION" ]; then
|
||||||
(cd $NVM_DIR; ls -dG $VERSION)
|
(cd $NVM_DIR; ls -dG "$VERSION")
|
||||||
else
|
else
|
||||||
echo "$VERSION"
|
echo "$VERSION"
|
||||||
fi
|
fi
|
||||||
|
@ -55,19 +60,22 @@ nvm()
|
||||||
echo "Node Version Manager"
|
echo "Node Version Manager"
|
||||||
echo
|
echo
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo " nvm help Show this message"
|
echo " nvm help Show this message"
|
||||||
echo " nvm install <version> Download and install a <version>"
|
echo " nvm install <version> Download and install a <version>"
|
||||||
echo " nvm use <version> Modify PATH to use <version>"
|
echo " nvm use <version> Modify PATH to use <version>"
|
||||||
echo " nvm ls List versions (installed versions are blue)"
|
echo " nvm ls List versions (installed versions are blue)"
|
||||||
echo " nvm ls <version> List versions matching a given description"
|
echo " nvm ls <version> List versions matching a given description"
|
||||||
echo " nvm deactivate Undo effects of NVM on current shell"
|
echo " nvm deactivate Undo effects of NVM on current shell"
|
||||||
echo " nvm sync Update the local cache of available versions"
|
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
|
||||||
echo "Example:"
|
echo "Example:"
|
||||||
echo " nvm install v0.2.5 Install a specific version number"
|
echo " nvm install v0.2.5 Install a specific version number"
|
||||||
echo " nvm use stable Use the stable release"
|
echo " nvm use stable Use the stable release"
|
||||||
echo " nvm install latest Install the latest, possibly unstable version"
|
echo " nvm install latest Install the latest, possibly unstable version"
|
||||||
echo " nvm use 0.3 Use the latest available 0.3.x release"
|
echo " nvm use 0.3 Use the latest available 0.3.x release"
|
||||||
|
echo " nvm alias default v0.3.6 Set v0.3.6 as the default"
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
"install" )
|
"install" )
|
||||||
|
@ -136,14 +144,46 @@ nvm()
|
||||||
"ls" )
|
"ls" )
|
||||||
if [ $# -ne 1 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
version $2
|
version $2
|
||||||
return;
|
return
|
||||||
fi
|
fi
|
||||||
version all
|
version all
|
||||||
for P in {stable,latest,current}; do
|
for P in {stable,latest,current}; do
|
||||||
echo -ne "$P: \t"; version $P
|
echo -ne "$P: \t"; version $P
|
||||||
done
|
done
|
||||||
|
nvm alias
|
||||||
echo "# use 'nvm sync' to update from nodejs.org"
|
echo "# use 'nvm sync' to update from nodejs.org"
|
||||||
;;
|
;;
|
||||||
|
"alias" )
|
||||||
|
if [ $# -le 2 ]; then
|
||||||
|
(cd $NVM_DIR/alias; for ALIAS in `ls $2* 2>/dev/null`; do
|
||||||
|
DEST=`cat $ALIAS`
|
||||||
|
VERSION=`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=`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" )
|
"sync" )
|
||||||
(cd $NVM_DIR
|
(cd $NVM_DIR
|
||||||
rm -f v* 2>/dev/null
|
rm -f v* 2>/dev/null
|
||||||
|
|
Loading…
Reference in New Issue