Adding shell var quotes in `nvm alias`

master
Jordan Harband 2014-09-23 16:36:17 -07:00
parent b962a590a2
commit 34b97bf76d
1 changed files with 11 additions and 10 deletions

21
nvm.sh
View File

@ -805,33 +805,34 @@ nvm() {
nvm_version current nvm_version current
;; ;;
"alias" ) "alias" )
mkdir -p $NVM_DIR/alias mkdir -p "$NVM_DIR/alias"
if [ $# -le 2 ]; then if [ $# -le 2 ]; then
local DEST local DEST
for ALIAS in $NVM_DIR/alias/$2*; do local ALIAS
for ALIAS in "$NVM_DIR"/alias/"$2"*; do
if [ -e "$ALIAS" ]; then if [ -e "$ALIAS" ]; then
DEST=`cat $ALIAS` DEST="$(cat "$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"
else else
echo "$(basename $ALIAS) -> $DEST (-> $VERSION)" echo "$(basename "$ALIAS") -> $DEST (-> $VERSION)"
fi fi
fi fi
done done
return return
fi fi
if [ -z "$3" ]; then if [ -z "$3" ]; then
rm -f $NVM_DIR/alias/$2 rm -f "$NVM_DIR/alias/$2"
echo "$2 -> *poof*" echo "$2 -> *poof*"
return return
fi fi
VERSION=`nvm_version $3` VERSION="$(nvm_version "$3")"
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" echo $3 > "$NVM_DIR/alias/$2"
if [ ! "$3" = "$VERSION" ]; then if [ ! "~$3" = "~$VERSION" ]; then
echo "$2 -> $3 (-> $VERSION)" echo "$2 -> $3 (-> $VERSION)"
else else
echo "$2 -> $3" echo "$2 -> $3"