diff --git a/nvm.sh b/nvm.sh index 6f107ec..da570cd 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" @@ -126,6 +127,33 @@ 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" && \ + mkdir -p "$NVM_DIR/src" && \ + 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) + + # TODO: Should rm any aliases that point to uninstalled version. + + # Run sync in order to restore version stub file in $NVM_DIR. + nvm sync 1>/dev/null + echo "Uninstalled node $VERSION" + ;; "deactivate" ) if [[ $PATH == *$NVM_DIR/*/bin* ]]; then export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:}