diff --git a/nvm.sh b/nvm.sh index 61b0012391..9a34618eb0 100644 --- a/nvm.sh +++ b/nvm.sh @@ -82,6 +82,7 @@ nvm() echo "Usage:" echo " nvm help Show this message" echo " nvm install Download and install a " + echo " nvm uninstall Uninstall a version" echo " nvm use Modify PATH to use " echo " nvm ls List versions (installed versions are blue)" echo " nvm ls List versions matching a given description" @@ -89,6 +90,7 @@ nvm() echo " nvm sync Update the local cache of available versions" echo " nvm alias [] Show all aliases beginning with " echo " nvm alias Set an alias named pointing to " + echo " nvm unalias Deletes the alias named " echo " nvm copy-packages Install global NPM packages contained in to current version" echo echo "Example:" @@ -96,7 +98,7 @@ nvm() 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 " nvm alias default v0.4.0 Set v0.4.0 as the default" echo ;; "install" ) @@ -135,6 +137,36 @@ nvm() echo "nvm: install $VERSION failed!" 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" ) if [[ $PATH == *$NVM_DIR/*/bin* ]]; then export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:} @@ -211,7 +243,7 @@ nvm() mkdir -p $NVM_DIR/alias VERSION=`nvm_version $3` if [ $? -ne 0 ]; then - echo "! WARNING: Version '$3' does not exist." >&2 + echo "! WARNING: Version '$3' does not exist." >&2 fi echo $3 > "$NVM_DIR/alias/$2" if [ ! "$3" = "$VERSION" ]; then @@ -221,6 +253,13 @@ nvm() echo "$2 -> $3" 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" ) [ "$NOCURL" ] && curl && return LATEST=`nvm_version latest`