<commit_before># Usage: scoop uninstall <app> [options]
# Summary: Uninstall an app
# Help: e.g. scoop uninstall git
#
# Options:
#   -g, --global   Uninstall a globally installed app
#   -p, --purge    Remove all persistent data
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
. "$psscriptroot\..\lib\help.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\shortcuts.ps1"
. "$psscriptroot\..\lib\psmodules.ps1"
. "$psscriptroot\..\lib\versions.ps1"
. "$psscriptroot\..\lib\getopt.ps1"
. "$psscriptroot\..\lib\config.ps1"

reset_aliases

# options
$opt, $apps, $err = getopt $args 'gp' 'global', 'purge'
if($err) { "scoop uninstall: $err"; exit 1 }
$global = $opt.g -or $opt.global
$purge = $opt.p -or $opt.purge

if(!$apps) { 'ERROR: <app> missing'; my_usage; exit 1 }

if($global -and !(is_admin)) {
    'ERROR: You need admin rights to uninstall global apps.'; exit 1
}

if($apps -eq 'scoop') {
    & "$psscriptroot\..\bin\uninstall.ps1" $global; exit
}

$apps = ensure_all_installed $apps $global
if(!$apps) { exit 0 }

:app_loop foreach($_ in $apps) {
    ($app, $global) = $_

    $version = current_version $app $global
    write-host "Uninstalling '$app' ($version)."

    $dir = versiondir $app $version $global
    $persist_dir = persistdir $app $global

    try {
        test-path $dir -ea stop | out-null
    } catch [unauthorizedaccessexception] {
        error "Access denied: $dir. You might need to restart."
        continue
    }

    $manifest = installed_manifest $app $version $global
    $install = install_info $app $version $global
    $architecture = $install.architecture

    run_uninstaller $manifest $architecture $dir
    rm_shims $manifest $global $architecture
    rm_startmenu_shortcuts $manifest $global $architecture

    # If a junction was used during install, that will have been used
    # as the reference directory. Otherwise it will just be the version
    # directory.
    $refdir = unlink_current $dir

    uninstall_psmodule $manifest $refdir $global

    env_rm_path $manifest $refdir $global
    env_rm $manifest $global

    try {
        # unlink all potential old link before doing recursive Remove-Item
        unlink_persist_data $dir
        Remove-Item -r $dir -ea stop -force
    } catch {
        if(test-path $dir) {
            error "Couldn't remove '$(friendly_path $dir)'; it may be in use."
            continue
        }
    }

    # remove older versions
    $old = @(versions $app $global)
    foreach($oldver in $old) {
        write-host "Removing older version ($oldver)."
        $dir = versiondir $app $oldver $global
        try {
            # unlink all potential old link before doing recursive Remove-Item
            unlink_persist_data $dir
            Remove-Item -r -force -ea stop $dir
        } catch {
            error "Couldn't remove '$(friendly_path $dir)'; it may be in use."
            continue app_loop
        }
    }

    if(@(versions $app).length -eq 0) {
        $appdir = appdir $app $global
        try {
            # if last install failed, the directory seems to be locked and this
            # will throw an error about the directory not existing
            Remove-Item -r $appdir -ea stop -force
        } catch {
            if((test-path $appdir)) { throw } # only throw if the dir still exists
        }
    }

    # purge persistant data
    if ($purge) {
        $persist_dir = persistdir $app $global

        if (Test-Path $persist_dir) {
            try {
                Remove-Item -r $persist_dir -ea stop -force
            } catch {
                error "Couldn't remove '$(friendly_path $persist_dir)'; it may be in use."
                continue
            }
        }
    }

    success "'$app' was uninstalled."
}

exit 0<commit_msg>Uninstall: Print purge step to console (#3123)<commit_after># Usage: scoop uninstall <app> [options]
# Summary: Uninstall an app
# Help: e.g. scoop uninstall git
#
# Options:
#   -g, --global   Uninstall a globally installed app
#   -p, --purge    Remove all persistent data
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
. "$psscriptroot\..\lib\help.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\shortcuts.ps1"
. "$psscriptroot\..\lib\psmodules.ps1"
. "$psscriptroot\..\lib\versions.ps1"
. "$psscriptroot\..\lib\getopt.ps1"
. "$psscriptroot\..\lib\config.ps1"

reset_aliases

# options
$opt, $apps, $err = getopt $args 'gp' 'global', 'purge'
if($err) { "scoop uninstall: $err"; exit 1 }
$global = $opt.g -or $opt.global
$purge = $opt.p -or $opt.purge

if(!$apps) { 'ERROR: <app> missing'; my_usage; exit 1 }

if($global -and !(is_admin)) {
    'ERROR: You need admin rights to uninstall global apps.'; exit 1
}

if($apps -eq 'scoop') {
    & "$psscriptroot\..\bin\uninstall.ps1" $global; exit
}

$apps = ensure_all_installed $apps $global
if(!$apps) { exit 0 }

:app_loop foreach($_ in $apps) {
    ($app, $global) = $_

    $version = current_version $app $global
    write-host "Uninstalling '$app' ($version)."

    $dir = versiondir $app $version $global
    $persist_dir = persistdir $app $global

    try {
        test-path $dir -ea stop | out-null
    } catch [unauthorizedaccessexception] {
        error "Access denied: $dir. You might need to restart."
        continue
    }

    $manifest = installed_manifest $app $version $global
    $install = install_info $app $version $global
    $architecture = $install.architecture

    run_uninstaller $manifest $architecture $dir
    rm_shims $manifest $global $architecture
    rm_startmenu_shortcuts $manifest $global $architecture

    # If a junction was used during install, that will have been used
    # as the reference directory. Otherwise it will just be the version
    # directory.
    $refdir = unlink_current $dir

    uninstall_psmodule $manifest $refdir $global

    env_rm_path $manifest $refdir $global
    env_rm $manifest $global

    try {
        # unlink all potential old link before doing recursive Remove-Item
        unlink_persist_data $dir
        Remove-Item -r $dir -ea stop -force
    } catch {
        if(test-path $dir) {
            error "Couldn't remove '$(friendly_path $dir)'; it may be in use."
            continue
        }
    }

    # remove older versions
    $old = @(versions $app $global)
    foreach($oldver in $old) {
        write-host "Removing older version ($oldver)."
        $dir = versiondir $app $oldver $global
        try {
            # unlink all potential old link before doing recursive Remove-Item
            unlink_persist_data $dir
            Remove-Item -r -force -ea stop $dir
        } catch {
            error "Couldn't remove '$(friendly_path $dir)'; it may be in use."
            continue app_loop
        }
    }

    if(@(versions $app).length -eq 0) {
        $appdir = appdir $app $global
        try {
            # if last install failed, the directory seems to be locked and this
            # will throw an error about the directory not existing
            Remove-Item -r $appdir -ea stop -force
        } catch {
            if((test-path $appdir)) { throw } # only throw if the dir still exists
        }
    }

    # purge persistant data
    if ($purge) {
        Write-Host 'Removing persisted data.'
        $persist_dir = persistdir $app $global

        if (Test-Path $persist_dir) {
            try {
                Remove-Item -r $persist_dir -ea stop -force
            } catch {
                error "Couldn't remove '$(friendly_path $persist_dir)'; it may be in use."
                continue
            }
        }
    }

    success "'$app' was uninstalled."
}

exit 0
{'fraction_non_alphanumeric': 0.1217572676313388, 'fraction_numerical': 0.004692999608916699, 'mean_word_length': 2.3634370889960543, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92828', 'n_tokens_mistral': 2504, 'n_tokens_neox': 2367, 'n_words': 741}