zls is now Get-ZfsItem with zls as an Alias

Modified code to use more 'PowerShell' centric methods, easier on the
formatting as table.
This commit is contained in:
Gal Szkolnik 2022-02-06 15:25:50 -05:00
parent 9eb99e1581
commit bb29930d51
3 changed files with 26 additions and 11 deletions

1
zfs/Aliases/zls.ps1 Normal file
View File

@ -0,0 +1 @@
Get-ZfsItem

25
zfs/Get-ZfsItem.ps1 Normal file
View File

@ -0,0 +1,25 @@
[CmdletBinding()]param(
[string[]]$Options='name,used,avail,refer,canmount,mounted,mountpoint'
)
$Options = $Options -join ','
if( $options -split ',' -notcontains 'name' ) { $options = "name,$Options" }
$local:prev = '';
zfs list -o $Options |
ForEach-Object { $_ -replace ' +',"`t" } |
ConvertFrom-Csv -Delimiter "`t" |
Where-Object Name -NotMatch '^rpool/var/lib/docker/' |
ForEach-Object {
$local:o = $_ | Select-Object @{L='-';E={''}},*
$local:tmpPrev = $o.Name -replace '^(\w+(\W\w+(\W\w+)?)?).*','$1';
if( $tmpPrev -notmatch "^$prev" -and $prev -notin ('','NAME') ) {
$o.'-' = "`n-"
};
$prev = $tmpPrev;
if( $o.MOUNTPOINT ) {
$o.MOUNTPOINT = $o.MOUNTPOINT -replace '^none$','<none>'
}
$o
} |
Format-Table -Wrap

View File

@ -1,11 +0,0 @@
$local:prev = "";
zfs list -o name,used,avail,refer,canmount,mounted,mountpoint $args |
grep -v 'docker/' |
ForEach-Object {
$local:tmpPrev = $_ -replace '^(\w+(\W\w+(\W\w+)?)?).*','$1';
if( $tmpPrev -notmatch "^$prev" -and $prev -notin ('','NAME') ) {
'-----------------'
};
$prev = $tmpPrev;
$_
}