Skip to content

Commit ef8363c

Browse files
rashil2000se35710
authored andcommitted
refactor(scoop-list): Allow list manipulation (ScoopInstaller#4718)
* refactor(scoop-list): Allow list manipulation * update changelog
1 parent 81e2095 commit ef8363c

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- **diagnostic** Skip check for 'exclusionPath' if defender realtime protect is disabled ([#4699](https://github.com/ScoopInstaller/Scoop/pull/4699))
4040
- **scoop-checkup** Skip 'check_windows_defender' when have not admin privileges ([#4699](https://github.com/ScoopInstaller/Scoop/pull/4699))
4141
- **scoop-checkup** Separate defender issues, mark as performance problem instead potential problem ([#4699](https://github.com/ScoopInstaller/Scoop/pull/4699))
42+
- **scoop-list:** Allow list manipulation ([#4718](https://github.com/ScoopInstaller/Scoop/pull/4718))
4243
- **shim:** Use `-file` instead of `-command` in ps1 script shims ([#4721](https://github.com/ScoopInstaller/Scoop/pull/4721))
4344

4445
### Builds

libexec/scoop-list.ps1

+40-33
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Help: Lists all installed apps, or the apps matching the supplied query.
44
param($query)
55

6-
. "$psscriptroot\..\lib\core.ps1"
7-
. "$psscriptroot\..\lib\versions.ps1"
8-
. "$psscriptroot\..\lib\manifest.ps1"
9-
. "$psscriptroot\..\lib\buckets.ps1"
6+
. "$PSScriptRoot\..\lib\core.ps1"
7+
. "$PSScriptRoot\..\lib\versions.ps1"
8+
. "$PSScriptRoot\..\lib\manifest.ps1"
9+
. "$PSScriptRoot\..\lib\buckets.ps1"
1010

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

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

19-
if($apps) {
20-
write-host "Installed apps$(if($query) { `" matching '$query'`"}): `n"
21-
$apps | Sort-Object { $_.name } | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
22-
$app = $_.name
23-
$global = $_.global
24-
$ver = Select-CurrentVersion -AppName $app -Global:$global
25-
26-
$install_info = install_info $app $ver $global
27-
write-host " $app " -NoNewline
28-
write-host -f DarkCyan $ver -NoNewline
29-
30-
if($global) { write-host -f DarkGreen ' *global*' -NoNewline }
31-
32-
if (!$install_info) { Write-Host ' *failed*' -ForegroundColor DarkRed -NoNewline }
33-
if ($install_info.hold) { Write-Host ' *hold*' -ForegroundColor DarkMagenta -NoNewline }
23+
$list = @()
24+
Write-Host "Installed apps$(if($query) { `" matching '$query'`"}):"
25+
$apps | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
26+
$app = $_.name
27+
$global = $_.global
28+
$item = [ordered]@{}
29+
$ver = Select-CurrentVersion -AppName $app -Global:$global
30+
$item.Name = $app
31+
$item.Version = $ver
32+
33+
$install_info_path = "$(versiondir $app $ver $global)\install.json"
34+
$install_info = $null
35+
if(Test-Path $install_info_path) {
36+
$install_info = parse_json $install_info_path
37+
}
3438

35-
if ($install_info.bucket) {
36-
write-host -f Yellow " [$($install_info.bucket)]" -NoNewline
37-
} elseif ($install_info.url) {
38-
write-host -f Yellow " [$($install_info.url)]" -NoNewline
39-
}
39+
$item.Source = if ($install_info.bucket) {
40+
$install_info.bucket
41+
} elseif ($install_info.url) {
42+
$install_info.url
43+
}
4044

41-
if ($install_info.architecture -and $def_arch -ne $install_info.architecture) {
42-
write-host -f DarkRed " {$($install_info.architecture)}" -NoNewline
43-
}
44-
write-host ''
45+
$info = @()
46+
if($global) { $info += "Global install" }
47+
if (!$install_info) { $info += "Install failed" }
48+
if ($install_info.hold) { $info += "Held package" }
49+
if ($install_info.architecture -and $def_arch -ne $install_info.architecture) {
50+
$info += $install_info.architecture
4551
}
46-
write-host ''
47-
exit 0
48-
} else {
49-
write-host "There aren't any apps installed."
50-
exit 1
52+
$item.Info = $info -join ', '
53+
54+
$list += $item
5155
}
56+
57+
$list.ForEach({[PSCustomObject]$_})
58+
exit 0

0 commit comments

Comments
 (0)