Created
November 26, 2024 17:02
-
-
Save milnak/3b90eadac4575493321c196e920bdabf to your computer and use it in GitHub Desktop.
Read scoop bucket files and output powershell objects suitable for filtering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arch_specific($prop, $manifest, $architecture) { | |
if ($manifest.architecture) { | |
$val = $manifest.architecture.$architecture.$prop | |
if ($val) { return $val } # else fallback to generic prop | |
} | |
if ($manifest.$prop) { return $manifest.$prop } | |
} | |
$scoopdir = Join-Path ([Environment]::GetFolderPath('UserProfile')) 'scoop' | |
$bucketsdir = "$scoopdir\buckets" | |
Get-ChildItem -LiteralPath $bucketsdir -Directory | ForEach-Object { | |
$bucketPath = Join-Path $bucketsdir $_ | |
$bucket = Join-Path $bucketPath 'bucket' | |
if ((Test-Path -LiteralPath $bucket -PathType Container)) { | |
# Bucket path exists | |
Get-ChildItem $bucket -Filter '*.json' | ForEach-Object { | |
# Create PSCustomObject | |
$manifestRaw = Get-Content -LiteralPath $_.FullName | |
$manifest = $manifestRaw | ConvertFrom-Json | |
[PSCustomObject]@{ | |
name = $($_ -replace '.*[\\/]([^\\/]+)\.json$', '$1') | |
description = if ($manifest.description) { $manifest.description } else { '' } | |
version = $manifest.version | |
bucket = $($_ -replace '.*buckets[\\/]([^\\/]+)(?:[\\/].*)', '$1') | |
manifest = $manifestRaw | |
binary = $( | |
$result = @() | |
@(arch_specific 'bin' $manifest $arch) | ForEach-Object { | |
if ($_ -is [System.Array]) { | |
$result += "$($_[1]).$($_[0].Split('.')[-1])" | |
} else { | |
$result += $_ | |
} | |
} | |
$result -replace '.*?([^\\/]+)?(\.(exe|bat|cmd|ps1|jar|py))$', '$1' -join ',' | |
) | |
shortcut = $( | |
$result = @() | |
@(arch_specific 'shortcuts' $manifest $arch) | ForEach-Object { | |
$result += $_[1] | |
} | |
$result -replace '.*?([^\\/]+$)', '$1' -join ',' | |
) | |
dependency = $manifest.depends -join ',' | |
suggest = $( | |
$suggest_output = @() | |
$manifest.suggest.PSObject.Properties | ForEach-Object { | |
$suggest_output += $_.Value -join ',' | |
} | |
$suggest_output -join ',' | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment