Add unalias and uninstall commands.

master
Evan Meagher 2011-08-19 18:00:25 -07:00
parent d5638cb241
commit 46302a25d2
1 changed files with 41 additions and 2 deletions

39
nvm.sh
View File

@ -82,6 +82,7 @@ nvm()
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 uninstall <version> Uninstall 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"
@ -89,6 +90,7 @@ nvm()
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 [<pattern>] Show all aliases beginning with <pattern>"
echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>" echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>"
echo " nvm unalias <name> Deletes the alias named <name>"
echo " nvm copy-packages <version> Install global NPM packages contained in <version> to current version" echo " nvm copy-packages <version> Install global NPM packages contained in <version> to current version"
echo echo
echo "Example:" echo "Example:"
@ -135,6 +137,36 @@ nvm()
echo "nvm: install $VERSION failed!" echo "nvm: install $VERSION failed!"
fi fi
;; ;;
"uninstall" )
[ $# -ne 2 ] && nvm help && return
if [[ $2 == `nvm_version` ]]; then
echo "nvm: Cannot uninstall currently-active node version, $2."
return
fi
VERSION=`nvm_version $2`
if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed yet"
return;
fi
# Delete all files related to target version.
(cd "$NVM_DIR" && \
rm -rf "node-$VERSION" 2>/dev/null && \
mkdir -p "$NVM_DIR/src" && \
cd "$NVM_DIR/src" && \
rm -f "node-$VERSION.tar.gz" 2>/dev/null && \
rm -rf "$NVM_DIR/$VERSION" 2>/dev/null)
echo "Uninstalled node $VERSION"
# Rm any aliases that point to uninstalled version.
for A in `grep -l $VERSION $NVM_DIR/alias/*`
do
nvm unalias `basename $A`
done
# Run sync in order to restore version stub file in $NVM_DIR.
nvm sync 1>/dev/null
;;
"deactivate" ) "deactivate" )
if [[ $PATH == *$NVM_DIR/*/bin* ]]; then if [[ $PATH == *$NVM_DIR/*/bin* ]]; then
export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:} export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:}
@ -221,6 +253,13 @@ nvm()
echo "$2 -> $3" echo "$2 -> $3"
fi fi
;; ;;
"unalias" )
mkdir -p $NVM_DIR/alias
[ $# -ne 2 ] && nvm help && return
[ ! -f $NVM_DIR/alias/$2 ] && echo "Alias $2 doesn't exist!" && return
rm -f $NVM_DIR/alias/$2
echo "Deleted alias $2"
;;
"sync" ) "sync" )
[ "$NOCURL" ] && curl && return [ "$NOCURL" ] && curl && return
LATEST=`nvm_version latest` LATEST=`nvm_version latest`