Skip to content

Instantly share code, notes, and snippets.

@phanirithvij
Last active January 29, 2022 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phanirithvij/721ad13ee857e0dbb695161812625a81 to your computer and use it in GitHub Desktop.
Save phanirithvij/721ad13ee857e0dbb695161812625a81 to your computer and use it in GitHub Desktop.
Scoop list installed apps from a bucket
# to install this exact revision
scoop install https://gist.githubusercontent.com/phanirithvij/721ad13ee857e0dbb695161812625a81/raw/cf89b9a6c996867becf169e8f85d221ceab1990f/bucketlist.json

# can also install from my bucket (which I might keep upto-date)
scoop bucket add scoop-rithvij https://github.com/phanirithvij/scop
scoop install scoop-rithvij/bucketlist
{
"version": "0.0.2",
"description": "List all installed manifests from a specified bucket",
"homepage": "https://gist.github.com/phanirithvij/721ad13ee857e0dbb695161812625a81",
"url": "https://gist.githubusercontent.com/phanirithvij/721ad13ee857e0dbb695161812625a81/raw/3eaff81254fdcdc96663f934913ceebb5aa1db2c/bucketlist.ps1",
"hash": "3bfc12f955d6f1323a8ca23f1c9493bbaf2c8c80fd94a279a54f780c22286b90",
"bin": "bucketlist.ps1",
"license": "MIT",
"post_install": [
"scoop alias add bucketlist \"powershell -File $(appsdir $global)/bucketlist/current/bucketlist.ps1 `$args\" \"List all installed manifests from a specified bucket\""
],
"uninstaller": {
"script": [
"scoop alias rm bucketlist"
]
}
}
# Summary: list all installed manifests from a bucket
param($bucket)
. "$env:scoop/apps/scoop/current/lib/core.ps1"
. "$env:scoop/apps/scoop/current/lib/versions.ps1"
. "$env:scoop/apps/scoop/current/lib/manifest.ps1"
# https://github.com/ScoopInstaller/Scoop/blob/5602083868ed04224ea8edf1ff0c3a2a3f6588b9/libexec/scoop-list.ps1
$local = installed_apps $false | ForEach-Object { @{ name = $_ } }
$global = installed_apps $true | ForEach-Object { @{ name = $_; global = $true } }
$apps = @($local) + @($global)
# https://stackoverflow.com/questions/60566336/how-does-one-output-bold-text-in-powershell
$esc = [char]27
if (!(test-path "$scoopdir/buckets/$bucket")) {
write-host 'WARN:' -ForegroundColor Yellow -NoNewline
write-host " Bucket directory: " -NoNewline
write-host -ForegroundColor White "$esc[4m$bucket$esc[0m" -NoNewline
write-host " missing in $scoopdir\buckets: "
}
# https://github.com/ScoopInstaller/Scoop/blob/5602083868ed04224ea8edf1ff0c3a2a3f6588b9/lib/manifest.ps1#L55
function install_info($app, $version, $global) {
$path = "$(versiondir $app $version $global)\install.json"
if(!(test-path $path)) { return $null }
parse_json $path
}
if($apps) {
write-host "Installed apps from $esc[4m$bucket$esc[0m$(if($query) { `" matching '$query'`"}): `n"
$apps = $apps | Sort-Object { $_.name } | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
$app = $_.name
$global = $_.global
$ver = Select-CurrentVersion -AppName $app -Global:$global
@{
app_install_info = install_info $app $ver $global
name = $app
global = $global
ver = $ver
}
}
$apps | Where-Object { !!$_.app_install_info -and $_.app_install_info.bucket -eq $bucket } | ForEach-Object {
$app = $_.name
$global = $_.global
$ver = $_.ver
write-host " $app " -NoNewline
write-host -f DarkCyan $ver -NoNewline
if($global) { write-host -f DarkGreen ' *global*' -NoNewline }
if ($_.app_install_info.hold) { write-host ' *hold*' -ForegroundColor DarkMagenta -NoNewline }
write-host ''
}
exit 0
} else {
write-host "There aren't any apps installed."
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment