=Fixed sz-df for better output

This commit is contained in:
Gal Szkolnik 2021-02-03 16:54:38 -05:00
parent 449a297d8b
commit 3d57308616
1 changed files with 13 additions and 12 deletions

View File

@ -15,21 +15,22 @@ function NewDataRow{param($Size,$Used,$Available,$Percent,$Source,$FSType,$Targe
Source = $Source
FSType = $FSType
Target = $Target
SourceLevel = $(if($Source[0] -eq '/') { 1 } else {0}) + $Source.Split('/').Count - 1
TargetLevel = $(if($Target[0] -eq '/') { 1 } else {0}) + $Target.Split('/').Count - 1
Group = $(switch( $FSType ) { 'zfs' { "$FSType`:$($Source.Split('/')[0])" } 'cifs' { "$FSType`:$($Source.Split('/')[2])" } default { $Source }} )
}
}
$local:df = @()
& df '--output=size,used,avail,pcent,source,fstype,target' |
& df '--output=size,used,avail,pcent,source,fstype,target' |
Select-Object -Skip 1 | ForEach-Object {
$local:df = $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries)
$local:df = $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries)
NewDataRow $df[0] $df[1] $df[2] $df[3] $df[4] $df[5] $df[6]
} | Where-Object {
$_.FSType -notin 'squashfs' -and $_.Target -notin 'zfs' -and ($_.FSType -ne 'zfs' -xor ($_.Source -match '^[^/]+(?:/[^/]+)$' -or $_.Target -match '^(?:/[^/]+)$'))
} | Sort-Object -Property FSType,Target
#$zpool_cmd = get-command zpool | Where-Object CommandType -eq 'Application' | Select-Object -ExpandProperty Source
#if( $zpool_cmd ) {
# $excludeType = '--exclude-type=zfs'
#}
} |
Group-Object -Property FSType |
ForEach-Object {
if( $_.Name -eq 'zfs' ) { $_.Group | Group-Object -Property Group | ForEach-Object { $_.Group | Select-Object -First 1 } }
else { $_.Group }
} |
Select-Object -Property "Size$SizeUnitName","Used$SizeUnitName","Available$SizeUnitName",'Used%',Source,FSType,Target |
Sort-Object -Property FSType,Target