2017-11-23 20:55:59 +08:00
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"
2023-02-11 03:55:37 +08:00
type -q zpool
or return
2017-11-23 20:55:59 +08:00
set -l pool ( string replace -r '/.*' '' -- $target )
set -l feature_name ""
if test -z " $pool "
2022-07-24 23:45:18 +08:00
set feature_name ( zpool get -H all 2 > /dev/null | string match -r " \s $feature \s " )
2017-11-23 20:55:59 +08:00
else
2022-07-24 23:45:18 +08:00
set feature_name ( zpool get -H all $pool 2 > /dev/null | string match -r " $pool \s $feature \s " )
2017-11-23 20:55:59 +08:00
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