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

Add extradiskinfo switch to show extra disk info such as volume label and total disk usage #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion winfetch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
Specify how to show information level for battery
.PARAMETER showdisks
Configure which disks are shown, use '-showdisks *' to show all.
.PARAMETER extradiskinfo
Show extra information about disks, such as the volume label and total disk size (if more than one disk is shown)
.PARAMETER showpkgs
Configure which package managers are shown, e.g. '-showpkgs winget,scoop,choco'.
.INPUTS
Expand All @@ -78,6 +80,7 @@ param(
[switch][alias('b')]$blink,
[switch][alias('s')]$stripansi,
[switch][alias('a')]$all,
[switch][alias('e')]$extradiskinfo,
[switch][alias('h')]$help,
[ValidateSet("text", "bar", "textbar", "bartext")][string]$cpustyle = "text",
[ValidateSet("text", "bar", "textbar", "bartext")][string]$memorystyle = "text",
Expand Down Expand Up @@ -791,17 +794,24 @@ function info_disk {
}
}

$totalDisksSize = 0
$totalDisksUsage = 0

[System.IO.DriveInfo]::GetDrives().ForEach{
$diskLetter = $_.Name.SubString(0,2)
$volumeLabel = $_.VolumeLabel

if ($showDisks.Contains($diskLetter) -or $showDisks.Contains("*")) {
try {
if ($_.TotalSize -gt 0) {
$used = $_.TotalSize - $_.AvailableFreeSpace
$usage = [math]::Floor(($used / $_.TotalSize * 100))

$totalDisksSize += $_.TotalSize
$totalDisksUsed += $used

[void]$lines.Add(@{
title = "Disk ($diskLetter)"
title = "Disk ($diskLetter" + $(If ($extradiskinfo) {" - $volumeLabel"} Else {""}) + ")"
content = get_level_info "" $diskstyle $usage "$(to_units $used) / $(to_units $_.TotalSize)"
})
}
Expand All @@ -814,6 +824,13 @@ function info_disk {
}
}

if ($extradiskinfo -and $lines.Count -gt 1) {
[void]$lines.Add(@{
title = "Total Disk Usage"
content = get_level_info "" $diskstyle ($totalDisksUsed / $totalDisksSize * 100) "$(to_units $totalDisksUsed) / $(to_units $totalDisksSize)"
})
}

return $lines
}

Expand Down