From bb29930d51b60e5a75df8b4293596768876cd35a Mon Sep 17 00:00:00 2001 From: Gal Szkolnik Date: Sun, 6 Feb 2022 15:25:50 -0500 Subject: [PATCH] zls is now Get-ZfsItem with zls as an Alias Modified code to use more 'PowerShell' centric methods, easier on the formatting as table. --- zfs/Aliases/zls.ps1 | 1 + zfs/Get-ZfsItem.ps1 | 25 +++++++++++++++++++++++++ zfs/zls.ps1 | 11 ----------- 3 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 zfs/Aliases/zls.ps1 create mode 100644 zfs/Get-ZfsItem.ps1 delete mode 100644 zfs/zls.ps1 diff --git a/zfs/Aliases/zls.ps1 b/zfs/Aliases/zls.ps1 new file mode 100644 index 0000000..1261402 --- /dev/null +++ b/zfs/Aliases/zls.ps1 @@ -0,0 +1 @@ +Get-ZfsItem diff --git a/zfs/Get-ZfsItem.ps1 b/zfs/Get-ZfsItem.ps1 new file mode 100644 index 0000000..3cc1d13 --- /dev/null +++ b/zfs/Get-ZfsItem.ps1 @@ -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$','' + } + $o + } | + Format-Table -Wrap + diff --git a/zfs/zls.ps1 b/zfs/zls.ps1 deleted file mode 100644 index cc156e1..0000000 --- a/zfs/zls.ps1 +++ /dev/null @@ -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; - $_ - } \ No newline at end of file