Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(scoop-list): Allow list manipulation #4718

Merged
merged 3 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- **diagnostic** Skip check for 'exclusionPath' if defender realtime protect is disabled ([#4699](https://github.com/ScoopInstaller/Scoop/pull/4699))
- **scoop-checkup** Skip 'check_windows_defender' when have not admin privileges ([#4699](https://github.com/ScoopInstaller/Scoop/pull/4699))
- **scoop-checkup** Separate defender issues, mark as performance problem instead potential problem ([#4699](https://github.com/ScoopInstaller/Scoop/pull/4699))
- **scoop-list:** Allow list manipulation ([#4718](https://github.com/ScoopInstaller/Scoop/pull/4718))
- **shim:** Use `-file` instead of `-command` in ps1 script shims ([#4721](https://github.com/ScoopInstaller/Scoop/pull/4721))

### Builds
Expand Down
73 changes: 40 additions & 33 deletions libexec/scoop-list.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Help: Lists all installed apps, or the apps matching the supplied query.
param($query)

. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\versions.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
. "$psscriptroot\..\lib\buckets.ps1"
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\versions.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
. "$PSScriptRoot\..\lib\buckets.ps1"

reset_aliases
$def_arch = default_architecture
Expand All @@ -15,37 +15,44 @@ $local = installed_apps $false | ForEach-Object { @{ name = $_ } }
$global = installed_apps $true | ForEach-Object { @{ name = $_; global = $true } }

$apps = @($local) + @($global)
if (-not $apps) {
Write-Host "There aren't any apps installed."
exit 1
}

if($apps) {
write-host "Installed apps$(if($query) { `" matching '$query'`"}): `n"
$apps | Sort-Object { $_.name } | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
$app = $_.name
$global = $_.global
$ver = Select-CurrentVersion -AppName $app -Global:$global

$install_info = install_info $app $ver $global
write-host " $app " -NoNewline
write-host -f DarkCyan $ver -NoNewline

if($global) { write-host -f DarkGreen ' *global*' -NoNewline }

if (!$install_info) { Write-Host ' *failed*' -ForegroundColor DarkRed -NoNewline }
if ($install_info.hold) { Write-Host ' *hold*' -ForegroundColor DarkMagenta -NoNewline }
$list = @()
Write-Host "Installed apps$(if($query) { `" matching '$query'`"}):"
$apps | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
$app = $_.name
$global = $_.global
$item = [ordered]@{}
$ver = Select-CurrentVersion -AppName $app -Global:$global
$item.Name = $app
$item.Version = $ver

$install_info_path = "$(versiondir $app $ver $global)\install.json"
$install_info = $null
if(Test-Path $install_info_path) {
$install_info = parse_json $install_info_path
}

if ($install_info.bucket) {
write-host -f Yellow " [$($install_info.bucket)]" -NoNewline
} elseif ($install_info.url) {
write-host -f Yellow " [$($install_info.url)]" -NoNewline
}
$item.Source = if ($install_info.bucket) {
$install_info.bucket
} elseif ($install_info.url) {
$install_info.url
}

if ($install_info.architecture -and $def_arch -ne $install_info.architecture) {
write-host -f DarkRed " {$($install_info.architecture)}" -NoNewline
}
write-host ''
$info = @()
if($global) { $info += "Global install" }
if (!$install_info) { $info += "Install failed" }
if ($install_info.hold) { $info += "Held package" }
if ($install_info.architecture -and $def_arch -ne $install_info.architecture) {
$info += $install_info.architecture
}
write-host ''
exit 0
} else {
write-host "There aren't any apps installed."
exit 1
$item.Info = $info -join ', '

$list += $item
}

$list.ForEach({[PSCustomObject]$_})
niheaven marked this conversation as resolved.
Show resolved Hide resolved
exit 0