Skip to content

Commit

Permalink
refactor(scoop-list): Allow list manipulation (ScoopInstaller#4718)
Browse files Browse the repository at this point in the history
* refactor(scoop-list): Allow list manipulation

* update changelog
  • Loading branch information
rashil2000 authored and se35710 committed Mar 8, 2022
1 parent 81e2095 commit ef8363c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
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]$_})
exit 0

0 comments on commit ef8363c

Please sign in to comment.