Skip to content

Instantly share code, notes, and snippets.

@ekishouTV
Last active November 18, 2023 04:39
Show Gist options
  • Save ekishouTV/af228c224accb8cca4da18fa01459257 to your computer and use it in GitHub Desktop.
Save ekishouTV/af228c224accb8cca4da18fa01459257 to your computer and use it in GitHub Desktop.
scoop-du: List directory usage - apps, buckets, cache, modules, persist and shims
# Usage: scoop du [options]
# Summary: List directory usage - apps, buckets, cache, modules, persist and shims
# Help: 'scoop du' List all (apps, buckets, cache, modules, persist and shims) .
#
# Options:
# -a, --apps Breakdown of apps
# -b, --buckets Breakdown of buckets
# -c, --cache Breakdown of cache
# -m, --modules Breakdown of modules
# -p, --persist Breakdown of persist
# -s, --shims Breakdown of shims
. "$PSScriptRoot\..\apps\scoop\current\lib\getopt.ps1"
$opt, $err = getopt $args 'abcmps' 'apps', 'buckets', 'cache', 'modules', 'persist', 'shims'
Update-FormatData "$PSScriptRoot\scoop-du.ps1xml"
filter measureDirectorySize {
ForEach-Object {
[PSCustomObject]@{
Name = $((Split-Path $_.FullName -Parent).Split('\') | Select-Object -Last 1) + '\' + $_.Name;
Size = [Math]::Round(
(
Get-ChildItem -Recurse -Force $_.FullName | Measure-Object -ErrorAction SilentlyContinue -Sum Length
).Sum / [Math]::Pow(1024, 3),
2
)
}
}
}
if ($opt.Count -eq 0) {
Get-ChildItem ~\scoop\ | measureDirectorySize | Add-Member -TypeName 'ScoopDu' -PassThru
}
else {
$directory_map = [PSCustomObject]@{
a = 'apps'
b = 'buckets'
c = 'cache'
m = 'modules'
p = 'persist'
s = 'shims'
apps = 'apps'
buckets = 'buckets'
cache = 'cache'
modules = 'modules'
persist = 'persist'
shims = 'shims'
}
$opt.Keys | Sort-Object | ForEach-Object { Get-ChildItem ~\scoop\$($directory_map.$_) } `
| measureDirectorySize | Add-Member -TypeName 'ScoopDu' -PassThru
}
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<ViewDefinitions>
<View>
<Name>ScoopDuType</Name>
<ViewSelectedBy>
<TypeName>ScoopDu</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Name</Label>
<Width>100</Width>
<Alignment>left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Size</Label>
<Width>7</Width>
<Alignment>right</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Size</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
@ekishouTV
Copy link
Author

ekishouTV commented Sep 23, 2023

Example:

PS> scoop du

Name                                                                                                    Size
----                                                                                                    ----
scoop\apps                                                                                             16.45
scoop\buckets                                                                                           0.15
scoop\cache                                                                                             4.16
scoop\modules                                                                                              0
scoop\persist                                                                                           3.52
scoop\shims                                                                                                0
PS> scoop du -ap

Name                                                                                                    Size
----                                                                                                    ----
apps\7zip                                                                                               0.02
apps\adb                                                                                                0.02
apps\aimp                                                                                               0.11
apps\audacious                                                                                          0.28
apps\audacity                                                                                           0.33
apps\colortool                                                                                             0
apps\crystaldiskinfo                                                                                    0.06
apps\dark                                                                                               0.01
apps\eac                                                                                                0.02
apps\gimp                                                                                               1.62
apps\git                                                                                                 2.4
apps\hwmonitor                                                                                          0.02
apps\imgburn                                                                                               0
apps\innounp                                                                                               0
apps\lessmsi                                                                                               0
apps\libreoffice                                                                                        1.35
apps\networkusageview                                                                                      0
apps\nodejs                                                                                                1
apps\obs-studio                                                                                         0.11
apps\openjdk                                                                                            0.92
apps\pwsh                                                                                               1.26
apps\python                                                                                             0.48
apps\rainmeter                                                                                          0.01
apps\reaper                                                                                             0.65
apps\rufus                                                                                                 0
apps\scoop                                                                                              0.02
apps\scoop-completion                                                                                      0
apps\screentogif                                                                                        0.49
apps\starship                                                                                           0.03
apps\sudo                                                                                                  0
apps\vlc                                                                                                0.17
apps\vscode                                                                                             4.99
apps\wincdemu                                                                                              0
apps\winfetch                                                                                              0
apps\winmerge                                                                                           0.08
persist\7zip                                                                                               0
persist\aimp                                                                                            0.01
persist\audacity                                                                                           0
persist\colortool                                                                                          0
persist\crystaldiskinfo                                                                                    0
persist\libreoffice                                                                                        0
persist\networkusageview                                                                                   0
persist\nodejs                                                                                          0.08
persist\obs-studio                                                                                      0.25
persist\obs-studio-small                                                                                   0
persist\pwsh                                                                                               0
persist\python                                                                                          0.02
persist\rainmeter                                                                                          0
persist\rufus                                                                                              0
persist\screentogif                                                                                        0
persist\vlc                                                                                                0
persist\vscode                                                                                          1.61
persist\winscp                                                                                             0
PS> scoop du --buckets       

Name                                                                                                    Size
----                                                                                                    ----
buckets\extras                                                                                          0.07
buckets\java                                                                                            0.02
buckets\main                                                                                            0.04
buckets\nerd-fonts                                                                                      0.01
buckets\nirsoft-alternative                                                                             0.01
buckets\nonportable                                                                                        0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment