mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Simplify and fix __fish_is_zfs_feature_enabled
(#9939)
* Simplify and fix `__fish_is_zfs_feature_enabled` Previously `__fish_is_zfs_feature_enabled` was doing `<whitespace>$queried_feature<whitespace>` pattern matching which was skipping the state part expected in the follow-up checking code. Passing the dataset/snapshot in a `target` argument is pointless. As none of the existing code attempts to do this plus it is also a private function (`__` prefix), rename of the argument and removal of extra text replacement should not be considered a breaking change. * Changed the `&& \` into `|| return` * Run `fish_indent`
This commit is contained in:
parent
27a11ef7fe
commit
21ddfabb8d
1 changed files with 6 additions and 16 deletions
|
@ -1,17 +1,7 @@
|
||||||
function __fish_is_zfs_feature_enabled -a feature target -d "Returns 0 if the given ZFS feature is available or enabled for the given full-path target (zpool or dataset), or any target if none given"
|
function __fish_is_zfs_feature_enabled \
|
||||||
type -q zpool
|
-a feature pool \
|
||||||
or return
|
-d "Returns 0 if the given ZFS pool feature is active or enabled for the given pool or for any pool if none specified"
|
||||||
set -l pool (string replace -r '/.*' '' -- $target)
|
|
||||||
set -l feature_name ""
|
type -q zpool || return
|
||||||
if test -z "$pool"
|
zpool get -H -o value $feature $pool 2>/dev/null | string match -rq '^(enabled|active)$'
|
||||||
set feature_name (zpool get -H all 2>/dev/null | string match -r "\s$feature\s")
|
|
||||||
else
|
|
||||||
set feature_name (zpool get -H all $pool 2>/dev/null | string match -r "$pool\s$feature\s")
|
|
||||||
end
|
|
||||||
if test $status -ne 0 # No such feature
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
set -l state (echo $feature_name | cut -f3)
|
|
||||||
string match -qr '(active|enabled)' -- $state
|
|
||||||
return $status
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue