This commit is contained in:
Dr. Kibitz 2014-03-12 15:30:29 +00:00
commit 028a5ae5c5
3 changed files with 20 additions and 11 deletions

23
nvm.sh
View File

@ -78,8 +78,8 @@ nvm_ls() {
return return
fi fi
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then if [ -h "$NVM_DIR/alias/$PATTERN" ]; then
nvm_version `cat $NVM_DIR/alias/$PATTERN` nvm_version $(basename $(readlink $NVM_DIR/alias/$PATTERN))
return return
fi 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
@ -373,9 +373,11 @@ nvm() {
echo "Uninstalled node $VERSION" echo "Uninstalled node $VERSION"
# Rm any aliases that point to uninstalled version. # Rm any aliases that point to uninstalled version.
for ALIAS in `\grep -l $VERSION $NVM_DIR/alias/* 2>/dev/null` for ALIAS in $NVM_DIR/alias/*
do do
nvm unalias `basename $ALIAS` if [ $(expr $(readlink $ALIAS) : ".*${VERSION}.*") -ne 0 ]; then
nvm unalias $(basename $ALIAS)
fi
done done
;; ;;
@ -491,7 +493,7 @@ nvm() {
local DEST local DEST
for ALIAS in $NVM_DIR/alias/$2*; do for ALIAS in $NVM_DIR/alias/$2*; do
if [ -e "$ALIAS" ]; then if [ -e "$ALIAS" ]; then
DEST=`cat $ALIAS` DEST=$(basename $(readlink $ALIAS))
VERSION=`nvm_version $DEST` VERSION=`nvm_version $DEST`
if [ "$DEST" = "$VERSION" ]; then if [ "$DEST" = "$VERSION" ]; then
echo "$(basename $ALIAS) -> $DEST" echo "$(basename $ALIAS) -> $DEST"
@ -512,17 +514,24 @@ nvm() {
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "! WARNING: Version '$3' does not exist." >&2 echo "! WARNING: Version '$3' does not exist." >&2
fi fi
echo $3 > "$NVM_DIR/alias/$2" # We are linking directories, so explicitly remove it rather than forcing with ln -f
if [ -h "$NVM_DIR/alias/$2" ]; then
rm -f "$NVM_DIR/alias/$2"
fi
if [ ! "$3" = "$VERSION" ]; then if [ ! "$3" = "$VERSION" ]; then
# link to other alias
ln -s "./$3" "$NVM_DIR/alias/$2"
echo "$2 -> $3 (-> $VERSION)" echo "$2 -> $3 (-> $VERSION)"
else else
# link to node installation
ln -s "../$3" "$NVM_DIR/alias/$2"
echo "$2 -> $3" echo "$2 -> $3"
fi fi
;; ;;
"unalias" ) "unalias" )
mkdir -p $NVM_DIR/alias mkdir -p $NVM_DIR/alias
[ $# -ne 2 ] && nvm help && return [ $# -ne 2 ] && nvm help && return
[ ! -f $NVM_DIR/alias/$2 ] && echo "Alias $2 doesn't exist!" && return [ ! -h $NVM_DIR/alias/$2 ] && echo "Alias $2 doesn't exist!" && return
rm -f $NVM_DIR/alias/$2 rm -f $NVM_DIR/alias/$2
echo "Deleted alias $2" echo "Deleted alias $2"
;; ;;

View File

@ -2,4 +2,4 @@
. ../../nvm.sh . ../../nvm.sh
nvm alias test v0.1.2 nvm alias test v0.1.2
[ $(cat ../../alias/test) = 'v0.1.2' ] [ -h ../../alias/test ] && [ $(readlink ../../alias/test) = '../v0.1.2' ]

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
echo v0.1.2 > ../../alias/test ln -s ../v0.1.2 ../../alias/test
. ../../nvm.sh . ../../nvm.sh
nvm unalias test nvm unalias test
! [ -e ../../alias/test ] ! [ -h ../../alias/test ]