Added completions/translations for zfs and zpool

This commit is contained in:
David Guyot 2017-11-23 13:55:59 +01:00 committed by Fabian Homborg
parent 5acbd32c2e
commit dcf9ce6fc5
22 changed files with 21567 additions and 2543 deletions

2749
po/de.po

File diff suppressed because it is too large Load diff

2560
po/en.po

File diff suppressed because it is too large Load diff

2538
po/fr.po

File diff suppressed because it is too large Load diff

2453
po/nb.po

File diff suppressed because it is too large Load diff

2453
po/nn.po

File diff suppressed because it is too large Load diff

2504
po/pl.po

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

2453
po/sv.po

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

476
share/completions/zfs.fish Normal file
View file

@ -0,0 +1,476 @@
# Fish completions for the OpenZFS zfs command
# Possible enhancements:
# - add a test to propose iSCSI and Trusted Extensions completions only when such system is present;
# - Illumos man pages suggests that it does not support nbmand nor atime mount option, so these properties should be proposed only when available
# - generally, propose properties only when the current OS and ZFS versions support them;
# - for the promote command, propose only eligible filesystems;
# - for the rollback command, propose only the most recent snapshot for each dataset, as it will not accept an intermediary snapshot;
# - for the release command, complete with existing tags;
# - for the diff command, complete the destination dataset of the diff;
# - for the program command, complete the script to be executed
# - for commands accepting several arguments of different types, propose arguments in the right order: for get, once the ZFS parameters have been given, only propose datasets
set OS ""
switch (uname)
case Linux
set OS "Linux"
case Darwin
set OS "macOS"
case FreeBSD
set OS "FreeBSD"
case SunOS
set OS "SunOS"
# Others?
case "*"
set OS "unknown"
end
function __fish_zfs_append -d "Internal completion function for appending string to the ZFS commandline"
set str (commandline -tc | string replace -rf '(.*,)[^,]*' '$1' | string replace -r -- '--.*=' '')
printf "%s\n" "$str"$argv
end
# Does the current invocation need a command?
function __fish_zfs_needs_command
set -l bookmark ""
if __fish_is_zfs_feature_enabled "feature@bookmarks"
set -l bookmark "|bookmark"
end
if commandline -c | grep -E -q " (\?|create|destroy|snap(shot)?|rollback|clone|promote|rename|list|set|get|inherit|upgrade|(user|group)space|(un?)?mount|(un)?share$bookmark|send|receive|recv|(un)?allow|holds?|release|diff|program) "
return 1
else
return 0
end
end
function __fish_zfs_using_command # ZFS command whose completions are looked for
set -l cmd (commandline -opc)
if test (count $cmd) -eq 1 # The token can only be 'zfs', so skip
return 2
end
if test $cmd[2] = $argv
return 0
else
return 1
end
end
function __fish_zfs_list_dataset_types
echo -e "filesystem\t"(_ "ZFS filesystem")
echo -e "snapshot\t"(_ "ZFS filesystem snapshot")
echo -e "volume\t"(_ "ZFS block storage device")
echo -e "bookmark\t"(_ "ZFS snapshot bookmark")
echo -e "all\t"(_ "Any ZFS dataset")
end
function __fish_zfs_list_source_types
echo -e "local\t"(_ "Dataset-specific value")
echo -e "default\t"(_ "Default ZFS value")
echo -e "inherited\t"(_ "Value inherited from parent dataset")
echo -e "received\t"(_ "Value received by 'zfs receive'")
echo -e "temporary\t"(_ "Value valid for the current mount")
echo -e "none\t"(_ "Read-only value")
end
function __fish_zfs_list_get_fields
echo -e "name\t"(_ "Dataset full name")
echo -e "property\t"(_ "Property")
echo -e "value\t"(_ "Property value")
echo -e "source\t"(_ "Property value origin")
end
function __fish_zfs_list_space_fields
echo -e "type\t"(_ "Identity type")
echo -e "name\t"(_ "Identity name")
echo -e "used\t"(_ "Space usage")
echo -e "quota\t"(_ "Space quota")
end
function __fish_zfs_list_userspace_types
echo -e "posixuser\t"(_ "POSIX user")
echo -e "smbuser\t"(_ "Samba user")
echo -e "all\t"(_ "Both types")
end
function __fish_zfs_list_groupspace_types
echo -e "posixgroup\t"(_ "POSIX group")
echo -e "smbgroup\t"(_ "Samba group")
echo -e "all\t"(_ "Both types")
end
function __fish_zfs_list_permissions
echo -e "allow\t"(_ "Also needs the permission to be allowed")
echo -e "clone\t"(_ "Also needs the 'create' and 'mount' permissions in the origin filesystem")
echo -e "create\t"(_ "Also needs the 'mount' permission")
echo -e "destroy\t"(_ "Also needs the 'mount' permission")
echo -e "mount"
echo -e "promote\t"(_ "Also needs the 'promote' and 'mount' permissions in the origin filesystem")
echo -e "receive\t"(_ "Also needs the 'create' and 'mount' permissions")
echo -e "rename\t"(_ "Also needs the 'create' and 'mount' permissions in the new parent")
echo -e "rollback\t"(_ "Also needs the 'mount' permission")
echo -e "send"
echo -e "share\t"(_ "For SMB and NFS shares")
echo -e "snapshot\t"(_ "Also needs the 'mount' permission")
echo -e "groupquota"
echo -e "groupused"
echo -e "userprop\t"(_ "Allows changing any user property")
echo -e "userquota"
echo -e "userused"
# The remaining code of the function is almost a duplicate of __fish_complete_zfs_rw_properties and __fish_complete_zfs_ro_properties, but almost only, hence the duplication
# RO properties
echo -e "volblocksize\t"(_ "Volume block size")
# R/W properties
echo -e "aclinherit\t"(_ "Inheritance of ACL entries")" (discard, noallow, restricted, passthrough, passthrough-x)"
echo -e "atime\t"(_ "Update access time on read")" (on, off)"
echo -e "canmount\t"(_ "Is the dataset mountable")" (on, off, noauto)"
set -l additional_cksum_algs ''
set -l additional_dedup_algs ''
if contains -- $OS FreeBSD SunOS
set additional_cksum_algs ", noparity"
end
if __fish_is_zfs_feature_enabled "feature@sha512"
set additional_cksum_algs "$additional_cksum_algs, sha512"
set additional_dedup_algs ", sha512[,verify]"
end
if __fish_is_zfs_feature_enabled "feature@skein"
set additional_cksum_algs "$additional_cksum_algs, skein"
set additional_dedup_algs "$additional_dedup_algs, skein[,verify]"
end
if __fish_is_zfs_feature_enabled "feature@edonr"
set additional_cksum_algs "$additional_cksum_algs, edonr"
set additional_dedup_algs "$additional_dedup_algs, edonr[,verify]"
end
echo -e "checksum\t"(_ "Data checksum")" (on, off, fletcher2, fletcher4, sha256$additional_cksum_algs)"
set -e additional_cksum_algs
set -l additional_compress_algs ''
if __fish_is_zfs_feature_enabled "feature@lz4_compress"
set additional_compress_algs ", lz4"
end
echo -e "compression\t"(_ "Compression algorithm")" (on, off, lzjb$additional_compress_algs, gzip, gzip-[1-9], zle)"
set -e additional_compress_algs
echo -e "copies\t"(_ "Number of copies of data")" (1, 2, 3)"
echo -e "dedup\t"(_ "Deduplication")" (on, off, verify, sha256[,verify]$additional_dedup_algs)"
set -e additional_dedup_algs
echo -e "devices\t"(_ "Are contained device nodes openable")" (on, off)"
echo -e "exec\t"(_ "Can contained executables be executed")" (on, off)"
echo -e "filesystem_limit\t"(_ "Max number of filesystems and volumes")" (COUNT, none)"
echo -e "mountpoint\t"(_ "Mountpoint")" (PATH, none, legacy)"
echo -e "primarycache\t"(_ "Which data to cache in ARC")" (all, none, metadata)"
echo -e "quota\t"(_ "Max size of dataset and children")" (SIZE, none)"
echo -e "snapshot_limit\t"(_ "Max number of snapshots")" (COUNT, none)"
echo -e "readonly\t"(_ "Read-only")" (on, off)"
echo -e "recordsize\t"(_ "Suggest block size")" (SIZE)"
echo -e "redundant_metadata\t"(_ "How redundant are the metadata")" (all, most)"
echo -e "refquota\t"(_ "Max space used by dataset itself")" (SIZE, none)"
echo -e "refreservation\t"(_ "Min space guaranteed to dataset itself")" (SIZE, none)"
echo -e "reservation\t"(_ "Min space guaranteed to dataset")" (SIZE, none)"
echo -e "secondarycache\t"(_ "Which data to cache in L2ARC")" (all, none, metadata)"
echo -e "setuid\t"(_ "Respect set-UID bit")" (on, off)"
echo -e "sharenfs\t"(_ "Share in NFS")" (on, off, OPTS)"
echo -e "logbias\t"(_ "Hint for handling of synchronous requests")" (latency, throughput)"
echo -e "snapdir\t"(_ "Hide .zfs directory")" (hidden, visible)"
echo -e "sync\t"(_ "Handle of synchronous requests")" (standard, always, disabled)"
echo -e "volsize\t"(_ "Volume logical size")" (SIZE)"
if test $OS = "SunOS"
echo -e "zoned\t"(_ "Managed from a non-global zone")" (on, off)"
echo -e "mlslabel\t"(_ "Can the dataset be mounted in a zone with Trusted Extensions enabled")" (LABEL, none)"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "sharesmb\t"(_ "Share in Samba")" (on, off)"
echo -e "shareiscsi\t"(_ "Share as an iSCSI target")" (on, off)"
echo -e "version\t"(_ "On-disk version of filesystem")" (1, 2, current)"
echo -e "vscan\t"(_ "Scan regular files for viruses on opening and closing")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
else if test $OS = "Linux"
echo -e "acltype\t"(_ "Use no ACL or POSIX ACL")" (noacl, posixacl)"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "relatime\t"(_ "Sometimes update access time on read")" (on, off)"
echo -e "shareiscsi\t"(_ "Share as an iSCSI target")" (on, off)"
echo -e "sharesmb\t"(_ "Share in Samba")" (on, off)"
echo -e "snapdev\t"(_ "Hide volume snapshots")" (hidden, visible)"
echo -e "version\t"(_ "On-disk version of filesystem")" (1, 2, current)"
echo -e "vscan\t"(_ "Scan regular files for viruses on opening and closing")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
else if test $OS = "FreeBSD"
echo -e "aclmode\t"(_ "How is ACL modified by chmod")" (discard, groupmask, passthrough, restricted)"
echo -e "volmode\t"(_ "How to expose volumes to OS")" (default, geom, dev, none)"
end
# Write-once properties
echo -e "normalization\t"(_ "Unicode normalization")" (none, formC, formD, formKC, formKD)"
echo -e "utf8only\t"(_ "Reject non-UTF-8-compliant filenames")" (on, off)"
if test $OS = "Linux"
echo -e "casesensitivity\t"(_ "Case sensitivity")" (sensitive, insensitive)"
else # FreeBSD, SunOS and virtually all others
echo -e "casesensitivity\t"(_ "Case sensitivity")" (sensitive, insensitive, mixed)"
end
# Permissions set; if none are found, or if permission sets are not supported, no output is expected, even an error
for i in (zpool list -o name -H); zfs allow $i; end | grep -o '@[[:alnum:]]*' | sort | uniq
end
complete -c zfs -f -n '__fish_zfs_needs_command' -s '?' -a '?' -d 'Display a help message'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'create' -d 'Create a volume or filesystem'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'destroy' -d 'Destroy a dataset'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'snapshot snap' -d 'Create a snapshot'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'rollback' -d 'Roll back a filesystem to a previous snapshot'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'clone' -d 'Create a clone of a snapshot'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'promote' -d 'Promotes a clone file system to no longer be dependent on its "origin" snapshot'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'rename' -d 'Rename a dataset'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'list' -d 'List dataset properties'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'set' -d 'Set a dataset property'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'get' -d 'Get one or several dataset properties'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'inherit' -d 'Set a dataset property to be inherited'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'upgrade' -d 'List upgradeable datasets, or upgrade one'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'userspace' -d 'Get dataset space consumed by each user'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'groupspace' -d 'Get dataset space consumed by each user group'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'mount' -d 'Mount a filesystem'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'unmount umount' -d 'Unmount a filesystem'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'share' -d 'Share a given filesystem, or all of them'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'unshare' -d 'Stop sharing a given filesystem, or all of them'
if __fish_is_zfs_feature_enabled 'feature@bookmarks'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'bookmark' -d 'Create a bookmark for a snapshot'
end
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'send' -d 'Output a stream representation of a dataset'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'receive recv' -d 'Write on disk a dataset from the stream representation given on standard input'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'allow' -d 'Delegate, or display delegations of, rights on a dataset to (groups of) users'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'unallow' -d 'Revoke delegations of rights on a dataset from (groups of) users'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'hold' -d 'Put a named hold on a snapshot'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'holds' -d 'List holds on a snapshot'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'release' -d 'Remove a named hold from a snapshot'
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'diff' -d 'List changed files between a snapshot, and a filesystem or a previous snapshot'
if test $OS = 'SunOS' # This is currently only supported under Illumos, but that will probably change
complete -c zfs -f -n '__fish_zfs_needs_command' -a 'program' -d 'Execute a ZFS Channel Program'
end
# Completions hereafter try to follow the man pages commands order, for maintainability, at the cost of multiple if statements
# create completions
complete -c zfs -f -n '__fish_zfs_using_command create' -s p -d 'Create all needed non-existing parent datasets'
if test $OS = 'Linux' # Only Linux supports the comma-separated format; others need multiple -o calls
complete -c zfs -x -n '__fish_zfs_using_command create' -s o -d 'Dataset property' -a '(__fish_zfs_append (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties))'
else
complete -c zfs -x -n '__fish_zfs_using_command create' -s o -d 'Dataset property' -a '(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties)'
end
# create completions for volumes; as -V is necessary to zfs to recognize a volume creation request, we use it as a condition to propose volume creation completions
# If -V is typed after -s or -b, zfs should accept it, but fish won't propose -s or -b, but, as these options are for volumes only, it seems reasonable to expect the user to ask for a volume, with -V, before giving its characteristics with -s or -b
complete -c zfs -x -n '__fish_zfs_using_command create' -s V -d 'Volume size'
complete -c zfs -f -n '__fish_zfs_using_command create; and __fish_contains_opt -s V' -s s -d 'Create a sparse volume'
complete -c zfs -x -n '__fish_zfs_using_command create; and __fish_contains_opt -s V' -s b -d 'Blocksize'
# destroy completions; as the dataset is the last item, we can't know yet if it's a snapshot, a bookmark or something else, so we can't separate snapshot-specific options from others
complete -c zfs -f -n '__fish_zfs_using_command destroy' -s r -d 'Recursively destroy children'
complete -c zfs -f -n '__fish_zfs_using_command destroy' -s R -d 'Recursively destroy all dependents'
complete -c zfs -f -n '__fish_zfs_using_command destroy' -s f -d 'Force unmounting'
complete -c zfs -f -n '__fish_zfs_using_command destroy' -s n -d 'Dry run'
complete -c zfs -f -n '__fish_zfs_using_command destroy' -s p -d 'Print machine-parsable verbose information'
complete -c zfs -f -n '__fish_zfs_using_command destroy' -s v -d 'Verbose mode'
complete -c zfs -f -n '__fish_zfs_using_command destroy' -s d -d 'Defer snapshot deletion'
complete -c zfs -x -n '__fish_zfs_using_command destroy' -d 'Dataset to destroy' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots; __fish_print_zfs_bookmarks)'
# snapshot completions
complete -c zfs -f -n '__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap' -s r -d 'Recursively snapshot children'
if test $OS = 'Linux' # Only Linux supports the comma-separated format; others need multiple -o calls
complete -c zfs -x -n '__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap' -s o -d 'Snapshot property' -a '(__fish_zfs_append (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties))'
else
complete -c zfs -x -n '__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap' -s o -d 'Snapshot property' -a '(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties)'
end
complete -c zfs -x -n '__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap' -d 'Dataset to snapshot' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)'
# rollback completions
complete -c zfs -f -n '__fish_zfs_using_command rollback' -s r -d 'Destroy later snapshot and bookmarks'
complete -c zfs -f -n '__fish_zfs_using_command rollback' -s R -d 'Recursively destroy later snapshot, bookmarks and clones'
complete -c zfs -f -n '__fish_zfs_using_command rollback; and __fish_contains_opt -s R' -s f -d 'Force unmounting of clones'
complete -c zfs -x -n '__fish_zfs_using_command rollback' -d 'Snapshot to roll back to' -a '(__fish_print_zfs_snapshots)'
# clone completions
complete -c zfs -f -n '__fish_zfs_using_command clone' -s p -d 'Create all needed non-existing parent datasets'
if test $OS = 'Linux' # Only Linux supports the comma-separated format; others need multiple -o calls
complete -c zfs -x -n '__fish_zfs_using_command clone' -s o -d 'Clone property' -a '(__fish_zfs_append (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties))'
else
complete -c zfs -x -n '__fish_zfs_using_command clone' -s o -d 'Clone property' -a '(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties)'
end
complete -c zfs -x -n '__fish_zfs_using_command clone' -d 'Snapshot to clone' -a '(__fish_print_zfs_snapshots)'
# promote completions
complete -c zfs -x -n '__fish_zfs_using_command promote' -d 'Clone to promote' -a '(__fish_print_zfs_filesystems)'
# rename completions; as the dataset is the last item, we can't know yet if it's a snapshot or not, we can't separate snapshot-specific option from others
complete -c zfs -f -n '__fish_zfs_using_command rename' -s p -d 'Create all needed non-existing parent datasets'
complete -c zfs -f -n '__fish_zfs_using_command rename' -s r -d 'Recursively rename children snapshots'
if test $OS = 'Linux'
complete -c zfs -f -n '__fish_zfs_using_command rename' -s f -d 'Force unmounting if needed'
else if test $OS = 'FreeBSD'
complete -c zfs -f -n '__fish_zfs_using_command rename' -s u -d 'Do not remount filesystems during rename'
complete -c zfs -f -n '__fish_zfs_using_command rename; and __fish_not_contain_opt -s u' -s f -d 'Force unmounting if needed'
end
complete -c zfs -x -n '__fish_zfs_using_command rename' -d 'Dataset to rename' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)'
# list completions
complete -c zfs -f -n '__fish_zfs_using_command list' -s H -d 'Print output in a machine-parsable format'
complete -c zfs -f -n '__fish_zfs_using_command list' -s r -d 'Operate recursively on datasets'
complete -c zfs -x -n '__fish_zfs_using_command list; and __fish_contains_opt -s r' -s d -d 'Maximum recursion depth'
complete -c zfs -x -n '__fish_zfs_using_command list' -s o -d 'Property to list' -a '(__fish_zfs_append (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties; __fish_complete_zfs_ro_properties; echo -e "name\t"(_ "Dataset name")"; echo -e "space\t"(_ "Space properties")"))'
complete -c zfs -f -n '__fish_zfs_using_command list' -s p -d 'Print parsable (exact) values for numbers'
complete -c zfs -x -n '__fish_zfs_using_command list; and __fish_not_contain_opt -s S' -s s -d 'Property to use for sorting output by ascending order' -a '(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties; __fish_complete_zfs_ro_properties; echo -e "name\t"(_ "Dataset name"))'
complete -c zfs -x -n '__fish_zfs_using_command list; and __fish_not_contain_opt -s s' -s S -d 'Property to use for sorting output by descending order' -a '(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties; __fish_complete_zfs_ro_properties; echo -e "name\t"(_ "Dataset name"))'
complete -c zfs -x -n '__fish_zfs_using_command list' -s t -d 'Dataset type' -a '(__fish_zfs_list_dataset_types)'
complete -c zfs -x -n '__fish_zfs_using_command list' -d 'Dataset which properties is to be listed' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)'
# set completions
complete -c zfs -x -n '__fish_zfs_using_command set' -d 'Property to set' -a '(__fish_complete_zfs_rw_properties)'
complete -c zfs -x -n '__fish_zfs_using_command set; and string match -q -r "zfs set \S+ " (commandline -c)' -d 'Dataset which property is to be setted' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)'
# get completions
complete -c zfs -f -n '__fish_zfs_using_command get' -s r -d 'Operate recursively on datasets'
complete -c zfs -x -n '__fish_zfs_using_command get; and __fish_contains_opt -s r' -s d -d 'Maximum recursion depth'
complete -c zfs -f -n '__fish_zfs_using_command get' -s H -d 'Print output in a machine-parsable format'
complete -c zfs -x -n '__fish_zfs_using_command get' -s o -d 'Fields to display' -a '(__fish_zfs_append (__fish_zfs_list_get_fields))'
complete -c zfs -x -n '__fish_zfs_using_command get' -s s -d 'Property source to display' -a '(__fish_zfs_append (__fish_zfs_list_source_types))'
complete -c zfs -f -n '__fish_zfs_using_command get' -s p -d 'Print parsable (exact) values for numbers'
complete -c zfs -x -n '__fish_zfs_using_command get' -s t -d 'Dataset type' -a '(__fish_zfs_append (__fish_zfs_list_dataset_types))'
complete -c zfs -x -n '__fish_zfs_using_command get' -d 'Property to get' -a '(__fish_zfs_append (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties; __fish_complete_zfs_ro_properties; echo "all"))'
complete -c zfs -x -n '__fish_zfs_using_command get' -d 'Dataset which properties is to be got' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)'
# inherit completions
complete -c zfs -f -n '__fish_zfs_using_command inherit' -s r -d 'Operate recursively on datasets'
complete -c zfs -f -n '__fish_zfs_using_command inherit' -s S -d 'Revert to the received value if available'
complete -c zfs -x -n '__fish_zfs_using_command inherit' -d 'Dataset which properties is to be inherited' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)'
# upgrade completions
complete -c zfs -f -n '__fish_zfs_using_command upgrade; and __fish_not_contain_opt -s a -s r -s V' -s v -d 'Verbose mode'
complete -c zfs -f -n '__fish_zfs_using_command upgrade; and __fish_not_contain_opt -s v' -s a -d 'Upgrade all eligible filesystems'
complete -c zfs -f -n '__fish_zfs_using_command upgrade; and __fish_not_contain_opt -s v' -s r -d 'Operate recursively on datasets'
complete -c zfs -x -n '__fish_zfs_using_command upgrade; and __fish_not_contain_opt -s v' -s V -d 'Upgrade to the specified version'
complete -c zfs -x -n '__fish_zfs_using_command upgrade; and __fish_not_contain_opt -s a' -d 'Filesystem to upgrade' -a '(__fish_print_zfs_filesystems)'
# userspace/groupspace completions
complete -c zfs -f -n '__fish_zfs_using_command userspace' -s n -d 'Print UID instead of user name'
complete -c zfs -f -n '__fish_zfs_using_command groupspace' -s n -d 'Print GID instead of group name'
complete -c zfs -f -n '__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace' -s H -d 'Print output in a machine-parsable format'
complete -c zfs -f -n '__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace' -s p -d 'Print parsable (exact) values for numbers'
complete -c zfs -x -n '__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace' -s o -d 'Field to display' -a '(__fish_zfs_append (__fish_zfs_list_space_fields))'
complete -c zfs -x -n '__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace; and __fish_not_contain_opt -s S' -s s -d 'Property to use for sorting output by ascending order' -a '__fish_zfs_list_space_fields'
complete -c zfs -x -n '__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace; and __fish_not_contain_opt -s s' -s S -d 'Property to use for sorting output by descending order' -a '__fish_zfs_list_space_fields'
complete -c zfs -x -n '__fish_zfs_using_command userspace' -s t -d 'Identity types to display' -a '(__fish_zfs_append (__fish_zfs_list_userspace_types))'
complete -c zfs -x -n '__fish_zfs_using_command groupspace' -s t -d 'Identity types to display' -a '(__fish_zfs_append (__fish_zfs_list_groupspace_types))'
complete -c zfs -f -n '__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace' -s i -d 'Translate S(amba)ID to POSIX ID'
complete -c zfs -x -n '__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace' -d 'Dataset which space usage is to be got' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_snapshots)'
# mount completions
complete -c zfs -x -n '__fish_zfs_using_command mount' -s o -d 'Temporary mount point property' -a '(__fish_zfs_append (__fish_complete_zfs_mountpoint_properties))'
complete -c zfs -f -n '__fish_zfs_using_command mount' -s v -d 'Report progress'
complete -c zfs -f -n '__fish_zfs_using_command mount' -s a -d 'Mount all available ZFS filesystems'
if contains -- $OS Linux SunOS
complete -c zfs -f -n '__fish_zfs_using_command mount' -s O -d 'Overlay mount'
end
complete -c zfs -x -n '__fish_zfs_using_command mount; and __fish_not_contain_opt -s a' -d 'Filesystem to mount' -a '(__fish_print_zfs_filesystems)'
# unmount completions
complete -c zfs -f -n '__fish_zfs_using_command unmount; or __fish_zfs_using_command umount' -s f -d 'Force unmounting if needed'
complete -c zfs -f -n '__fish_zfs_using_command unmount; or __fish_zfs_using_command umount' -s a -d 'Unmount all available ZFS filesystems'
complete -c zfs -x -n '__fish_zfs_using_command unmount; or __fish_zfs_using_command umount; and __fish_not_contain_opt -s a' -d 'Filesystem to unmount' -a '(__fish_print_zfs_filesystems; __fish_print_mounted)'
# share completions
complete -c zfs -f -n '__fish_zfs_using_command share' -s a -d 'Share all eligible ZFS filesystems'
complete -c zfs -x -n '__fish_zfs_using_command share; and __fish_not_contain_opt -s a' -d 'Filesystem to share' -a '(__fish_print_zfs_filesystems)'
# unshare completions
complete -c zfs -f -n '__fish_zfs_using_command unshare' -s a -d 'Unshare all shared ZFS filesystems'
complete -c zfs -x -n '__fish_zfs_using_command unshare; and __fish_not_contain_opt -s a' -d 'Filesystem to unshare' -a '(__fish_print_zfs_filesystems; __fish_print_mounted)'
# bookmark completions
if __fish_is_zfs_feature_enabled 'feature@bookmarks'
complete -c zfs -x -n '__fish_zfs_using_command bookmark' -d 'Snapshot to bookmark' -a '(__fish_print_zfs_snapshots)'
end
# send completions
complete -c zfs -x -n '__fish_zfs_using_command send' -s i -d 'Generate incremental stream from snapshot' -a '(__fish_print_zfs_snapshots; __fish_print_zfs_bookmarks)'
complete -c zfs -x -n '__fish_zfs_using_command send' -s I -d 'Generate incremental stream from snapshot, even with intermediary snapshots' -a '(__fish_print_zfs_snapshots)'
if test $OS = 'SunOS'
complete -c zfs -f -n '__fish_zfs_using_command send' -s R -l replicate -d 'Include children in replication stream'
complete -c zfs -f -n '__fish_zfs_using_command send' -s D -l dedup -d 'Generate a deduplicated stream'
complete -c zfs -f -n '__fish_zfs_using_command send; and __fish_is_zfs_feature_enabled "feature@large_blocks"' -s L -l large-block -d 'Allow the presence of larger blocks than 128 kiB'
complete -c zfs -f -n '__fish_zfs_using_command send; and __fish_is_zfs_feature_enabled "feature@embedded_data"' -s e -l embed -d 'Generate a more compact stream by using WRITE_EMBEDDED records'
complete -c zfs -f -n '__fish_zfs_using_command send' -s P -l parsable -d 'Print verbose information about the stream in a machine-parsable format'
complete -c zfs -f -n '__fish_zfs_using_command send' -s c -l compressed -d 'Generate compressed stream'
complete -c zfs -f -n '__fish_zfs_using_command send' -s n -l dryrun -d 'Dry run'
complete -c zfs -f -n '__fish_zfs_using_command send; and __fish_not_contain_opt -s R' -s p -l props -d 'Include dataset properties'
complete -c zfs -f -n '__fish_zfs_using_command send' -s v -l verbose -d 'Print verbose information about the stream'
else
complete -c zfs -f -n '__fish_zfs_using_command send' -s R -d 'Include children in replication stream'
complete -c zfs -f -n '__fish_zfs_using_command send' -s D -d 'Generate a deduplicated stream'
complete -c zfs -f -n '__fish_zfs_using_command send; and __fish_is_zfs_feature_enabled "feature@large_blocks"' -s L -d 'Allow the presence of larger blocks than 128 kiB'
complete -c zfs -f -n '__fish_zfs_using_command send; and __fish_is_zfs_feature_enabled "feature@embedded_data"' -s e -d 'Generate a more compact stream by using WRITE_EMBEDDED records'
complete -c zfs -f -n '__fish_zfs_using_command send' -s P -d 'Print verbose information about the stream in a machine-parsable format'
complete -c zfs -f -n '__fish_zfs_using_command send' -s n -d 'Dry run'
complete -c zfs -f -n '__fish_zfs_using_command send; and __fish_not_contain_opt -s R' -s p -d 'Include dataset properties'
complete -c zfs -f -n '__fish_zfs_using_command send' -s v -d 'Print verbose information about the stream'
end
complete -c zfs -x -n '__fish_zfs_using_command send' -d 'Dataset to send' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)'
# receive completions
complete -c zfs -f -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv' -s v -d 'Print verbose information about the stream and the time spent processing it'
complete -c zfs -f -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv' -s n -d 'Dry run: do not actually receive the stream'
complete -c zfs -f -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv' -s F -d 'Force rollback to the most recent snapshot'
complete -c zfs -f -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv' -s u -d 'Unmount the target filesystem'
complete -c zfs -f -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv; and __fish_not_contain_opt -s e' -s d -d 'Discard the first element of the path of the sent snapshot'
complete -c zfs -f -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv; and __fish_not_contain_opt -s d' -s e -d 'Discard all but the last element of the path of the sent snapshot'
if test $OS = "SunOS"
complete -c zfs -x -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv' -s o -d 'Force the stream to be received as a clone of the given snapshot' -a 'origin'
end
if __fish_is_zfs_feature_enabled "feature@extensible_dataset"
complete -c zfs -f -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv' -s s -d 'On transfer interruption, store a receive_resume_token for resumption'
end
complete -c zfs -x -n '__fish_zfs_using_command receive; or __fish_zfs_using_command recv' -d 'Dataset to receive' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)'
# allow completions
complete -c zfs -f -n '__fish_zfs_using_command allow; and __fish_not_contain_opt -s d' -s l -d 'Delegate permissions only on the specified dataset'
complete -c zfs -f -n '__fish_zfs_using_command allow; and __fish_not_contain_opt -s l' -s d -d 'Delegate permissions only on the descendents dataset'
complete -c zfs -x -n '__fish_zfs_using_command allow; and __fish_not_contain_opt -s e' -s u -d 'User to delegate permissions to' -a '(__fish_zfs_append (__fish_complete_users))'
complete -c zfs -x -n '__fish_zfs_using_command allow; and __fish_not_contain_opt -s e' -s g -d 'Group to delegate permissions to' -a '(__fish_zfs_append (__fish_complete_groups))'
if contains -- $OS SunOS FreeBSD
complete -c zfs -f -n '__fish_zfs_using_command allow; and __fish_not_contain_opt -s u -s g -s e' -a 'everyone' -d 'Delegate permission to everyone'
end
complete -c zfs -x -n '__fish_zfs_using_command allow; and __fish_not_contain_opt -s u -s g everyone' -s e -d 'Delegate permission to everyone'
complete -c zfs -x -n '__fish_zfs_using_command allow; and __fish_not_contain_opt -s l -s d -s e -s g -s u -s s' -s c -d 'Delegate permissions only to the creator of later descendent datasets' -a '(__fish_zfs_append (__fish_zfs_list_permissions))'
complete -c zfs -x -n '__fish_zfs_using_command allow; and __fish_not_contain_opt -s l -s d -s e -s g -s u -s c' -s s -d 'Create a permission set or add permissions to an existing one'
complete -c zfs -x -n '__fish_zfs_using_command allow' -d 'Dataset on which delegation is to be applied' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)'
# unallow completions
complete -c zfs -f -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s d' -s l -d 'Remove permissions only on the specified dataset'
complete -c zfs -f -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s l' -s d -d 'Remove permissions only on the descendents dataset'
complete -c zfs -x -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s e' -s u -d 'User to remove permissions from' -a '(__fish_zfs_append (__fish_complete_users))'
complete -c zfs -x -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s e' -s g -d 'Group to remove permissions from' -a '(__fish_zfs_append (__fish_complete_groups))'
complete -c zfs -x -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s u -s g everyone' -s e -d 'Remove permission from everyone'
complete -c zfs -x -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s l -s d -s e -s g -s u -s s' -s c -d 'Remove permissions only on later created descendent datasets' -a '(__fish_zfs_append (__fish_zfs_list_permissions))'
complete -c zfs -x -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s l -s d -s e -s g -s u -s c' -s s -d 'Remove a permission set or remove permissions from an existing one'
if test $OS = 'SunOS'
complete -c zfs -f -n '__fish_zfs_using_command unallow' -s r -d 'Remove permissions recursively'
complete -c zfs -f -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s u -s g -s e' -a 'everyone' -d 'Remove permission from everyone'
else if test $OS = 'FreeBSD'
complete -c zfs -f -n '__fish_zfs_using_command unallow; and __fish_not_contain_opt -s u -s g -s e' -a 'everyone' -d 'Remove permission from everyone'
end
complete -c zfs -x -n '__fish_zfs_using_command unallow' -d 'Dataset on which delegation is to be removed' -a '(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)'
# hold completions
complete -c zfs -f -n '__fish_zfs_using_command hold' -s r -d 'Apply hold recursively'
complete -c zfs -x -n '__fish_zfs_using_command hold' -d 'Snapshot on which hold is to be applied' -a '(__fish_print_zfs_snapshots)'
# holds completions
complete -c zfs -f -n '__fish_zfs_using_command holds' -s r -d 'List holds recursively'
complete -c zfs -x -n '__fish_zfs_using_command holds' -d 'Snapshot which holds are to be listed' -a '(__fish_print_zfs_snapshots)'
# release completions
complete -c zfs -f -n '__fish_zfs_using_command release' -s r -d 'Release hold recursively'
complete -c zfs -x -n '__fish_zfs_using_command release' -d 'Snapshot from which hold is to be removed' -a '(__fish_print_zfs_snapshots)'
# diff completions
complete -c zfs -f -n '__fish_zfs_using_command diff' -s F -d 'Display file type (à la ls -F)'
complete -c zfs -f -n '__fish_zfs_using_command diff' -s H -d 'Print output in a machine-parsable format'
complete -c zfs -f -n '__fish_zfs_using_command diff' -s t -d 'Display inode change time'
complete -c zfs -x -n '__fish_zfs_using_command diff' -d 'Source snapshot for the diff' -a '(__fish_print_zfs_snapshots)'
# program completions
if test $OS = 'SunOS' # This is currently only supported under Illumos, but that will probably change
complete -c zfs -x -n '__fish_zfs_using_command program' -s t -d 'Execution timeout'
complete -c zfs -x -n '__fish_zfs_using_command program' -s t -d 'Execution memory limit'
complete -c zfs -x -n '__fish_zfs_using_command program' -d 'Pool which program will be executed on' -a '(__fish_complete_zfs_pools)'
end

View file

@ -0,0 +1,421 @@
# Fish completions for the OpenZFS zpool command
# Possible improvements:
# - whenever possible, propose designation of vdevs using their GUID
# - for eligible commands, with arguments of different types, only propose second type completions after the first have been selected; for instance, only propose pool members for offline command
# - this has been written mainly from manpages, which are known to be out-of-sync with the real feature set; some discrepancies have been addressed, but it is highly likely that others still lie
set OS ""
switch (uname)
case Linux
set OS "Linux"
case Darwin
set OS "macOS"
case FreeBSD
set OS "FreeBSD"
case SunOS
set OS "SunOS"
# Others?
case "*"
set OS "unknown"
end
# Does the current invocation need a command?
function __fish_zpool_needs_command
if commandline -c | grep -E -q " (\?|add|attach|clear|create|destroy|detach|events|get|history|import|iostat|labelclear|list|offline|online|reguid|reopen|remove|replace|scrub|set|split|status|upgrade) "
return 1
else
return 0
end
end
function __fish_zpool_using_command # zpool command whose completions are looked for
set -l cmd (commandline -opc)
if test (count $cmd) -eq 1 # The token can only be 'zpool', so skip
return 2
end
if test $cmd[2] = $argv
return 0
else
return 1
end
end
function __fish_zpool_append -d "Internal completion function for appending string to the zpool commandline"
set str (commandline -tc| sed -ne "s/\(.*,\)[^,]*/\1/p"|sed -e "s/--.*=//")
printf "%s\n" "$str"$argv
end
function __fish_zpool_list_used_vdevs -a pool
if test -z "$pool"
zpool list -H -v | grep -E "^\s" | cut -f2 | grep -x -E -v "(spare|log|cache|mirror|raidz.?)"
else
zpool list -H -v $pool | grep -E "^\s" | cut -f2 | grep -x -E -v "(spare|log|cache|mirror|raidz.?)"
end
end
function __fish_zpool_list_available_vdevs
if test $OS = 'Linux'
find /dev -type b | cut -d'/' -f3
else if test $OS = 'FreeBSD'
for i in (camcontrol devlist | cut -d "(" -f 2 | cut -d "," -f 1); ls /dev | grep "^$i"; end
else if test $OS = 'SunOS'
ls /dev/dsk
end
end
function __fish_zpool_complete_vdevs
# As this function is to be called for completions only when necessary, we don't need to verify that it is relevant for the specified command; this is to be decided by calling, or not, the current function for command completions
# We can display the physical devices, as they are relevant whereas we are in a vdev definition or not
__fish_zpool_list_available_vdevs
# First, reverse token list to analyze it from the end
set -l reversedTokens ""
for i in (commandline -co)
set reversedTokens "$i $reversedTokens"
end
set -l tokens 0
for i in (echo "$reversedTokens" | sed "s/ /\n/g")
switch $i
case spare log cache # At least 1 item expected
if test $tokens -ge 1
__fish_zpool_list_vdev_types
end
return
case mirror raidz raidz1 # At least 2 items expected
if test $tokens -ge 2
__fish_zpool_list_vdev_types
end
return
case raidz2 # At least 3 items expected
if test $tokens -ge 3
__fish_zpool_list_vdev_types
end
return
case raidz3 # At least 4 items expected
if test $tokens -ge 4
__fish_zpool_list_vdev_types
end
return
# Here, we accept any possible zpool command; this way, the developper will not have to augment or reduce the list when adding the current function to or removing it from the completions for the said command
case \? add attach clear create destroy detach events get history import iostat labelclear list offline online reguid reopen remove replace scrub set split status upgrade
__fish_zpool_list_vdev_types
return
case "" # Au cas où
echo "" > /dev/null
case "*"
if echo "$i" | grep -q -E '^((-.*)|(.*(=|,).*))$' # The token is an option or an option argument; as no option uses a vdev as its argument, we can abandon commandline parsing
__fish_zpool_list_vdev_types
return
end
end
set tokens (math $tokens+1)
end
end
function __fish_zpool_list_get_fields
echo -e "name\t"(_ "Pool full name")
echo -e "property\t"(_ "Property")
echo -e "value\t"(_ "Property value")
echo -e "source\t"(_ "Property value origin")
end
function __fish_zpool_list_vdev_types
echo -e "mirror\t"(_ "Mirror of at least two devices")
echo -e "raidz\t"(_ "ZFS RAID-5 variant, single parity")
echo -e "raidz1\t"(_ "ZFS RAID-5 variant, single parity")
echo -e "raidz2\t"(_ "ZFS RAID-5 variant, double parity")
echo -e "raidz3\t"(_ "ZFS RAID-5 variant, triple parity")
echo -e "spare\t"(_ "Pseudo vdev for pool hot spares")
echo -e "log\t"(_ "SLOG device")
echo -e "cache\t"(_ "L2ARC device")
end
function __fish_zpool_list_ro_properties
echo -e "alloc\t"(_ "Physically allocated space")
if contains -- $OS SunOS Linux
echo -e "available\t"(_ "Available space")
echo -e "avail\t"(_ "Available space")
end
if test $OS = 'SunOS'
echo -e "bootsize\t"(_ "System boot partition size")
end
echo -e "capacity\t"(_ "Usage percentage of pool")
echo -e "dedupratio\t"(_ "Deduplication ratio")
echo -e "expandsize\t"(_ "Amount of uninitialized space within the pool")
echo -e "fragmentation\t"(_ "Fragmentation percentage of pool")
echo -e "free\t"(_ "Free pool space")
echo -e "freeing\t"(_ "Remaining pool space to be freed")
echo -e "guid\t"(_ "Pool GUID")
echo -e "health\t"(_ "Current pool health")
echo -e "size\t"(_ "Total pool space")
echo -e "used\t"(_ "Used pool space")
# Unsupported features
for i in (zpool list -o all | head -n1 | tr -s "[:blank:]" | tr ' ' '\n' | tr "[:upper:]" "[:lower:]" | grep unsupported); echo $i; end
end
function __fish_zpool_list_device_properties
echo -e "ashift\t"(_ "Pool sector size exponent")" (COUNT)"
end
function __fish_zpool_list_writeonce_properties
echo -e "altroot\t"(_ "Alternate root directory")" (PATH)"
end
function __fish_zpool_list_importtime_properties
echo -e "altroot\t"(_ "Alternate root directory")" (PATH)"
echo -e "readonly\t"(_ "Import pool in read-only mode")" (on, off)"
echo -e "rdonly\t"(_ "Import pool in read-only mode")" (on, off)"
end
function __fish_zpool_list_rw_properties
echo -e "autoexpand\t"(_ "Automatic pool expansion on LUN growing")" (on, off)"
echo -e "expand\t"(_ "Automatic pool expansion on LUN growing")" (on, off)"
echo -e "autoreplace\t"(_ "Automatic use of replacement device")" (on, off)"
echo -e "replace\t"(_ "Automatic use of replacement device")" (on, off)"
echo -e "bootfs\t"(_ "Default bootable dataset")" (POOL/DATASET)"
echo -e "cachefile\t"(_ "Pool configuration cache")" (PATH, none, '')"
echo -e "comment\t"(_ "Comment about the pool")" (COMMENT)"
echo -e "dedupditto\t"(_ "Threshold for writting a ditto copy of deduplicated blocks")" (COUNT)"
echo -e "delegation\t"(_ "Allow rights delegation on the pool")" (on, off)"
echo -e "failmode\t"(_ "Behavior in case of catastrophic pool failure")" (wait, continue, panic)"
echo -e "listsnaps\t"(_ "Display snapshots even if 'zfs list' does not use '-t'")" (on, off)"
echo -e "version\t"(_ "On-disk version of pool")" (VERSION)"
# Feature properties
for featureLong in (zpool list -o all | tr -s "[:blank:]" | tr ' ' '\n' | tr "[:upper:]" "[:lower:]" | grep '^feature@')
set -l featureShort (echo $featureLong | sed -e 's/feature@\(.*\)/\1/g')
set featureLong (echo -e "$featureLong\t")
printf (_ "%sEnable the %s feature\n") $featureLong $featureShort
end
end
complete -c zpool -f -n '__fish_zpool_needs_command' -s '?' -d 'Display a help message'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'add' -d 'Add new virtual devices to pool'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'attach' -d 'Attach virtual device to a pool device'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'clear' -d 'Clear devices errors in pool'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'create' -d 'Create a new storage pool'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'destroy' -d 'Destroy a storage pool'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'detach' -d 'Detach virtual device from a mirroring pool'
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'events' -d 'Display pool event log'
end
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'export' -d 'Export a pool'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'get' -d 'Get one or several pool properties'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'history' -d 'Display pool command history'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'import' -d 'List importable pools, or import some'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'iostat' -d 'Display pool I/O stats'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'labelclear' -d 'Remove ZFS label information from the specified device'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'list' -d 'List pools with health status and space usage'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'offline' -d 'Take the specified devices offline'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'online' -d 'Bring the specified devices back online'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'reguid' -d 'Reset pool GUID'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'remove' -d 'Remove virtual devices from pool'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'reopen' -d 'Reopen pool devices'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'replace' -d 'Replace a pool virtual device'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'scrub' -d 'Start or stop scrubbing'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'set' -d 'Set a pool property'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'split' -d 'Create a pool by splitting an existing mirror one'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'status' -d 'Display detailed pool health status'
complete -c zpool -f -n '__fish_zpool_needs_command' -a 'upgrade' -d 'List upgradeable pools, or upgrade one'
# add completions
complete -c zpool -f -n '__fish_zpool_using_command add' -s f -d 'Force use of virtual device'
complete -c zpool -f -n '__fish_zpool_using_command add' -s n -d 'Dry run: only display resulting configuration'
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_using_command add' -s g -d 'Display virtual device GUID instead of device name'
complete -c zpool -f -n '__fish_zpool_using_command add' -s L -d 'Resolve device path symbolic links'
complete -c zpool -f -n '__fish_zpool_using_command add' -s P -d 'Display device full path'
complete -c zpool -x -n '__fish_zpool_using_command add' -s o -d 'Pool property' -a '(__fish_zpool_list_device_properties)'
end
complete -c zpool -x -n '__fish_zpool_using_command add' -d 'Pool to add virtual devices to' -a '(__fish_complete_zfs_pools)'
complete -c zpool -x -n '__fish_zpool_using_command add' -d 'Virtual device to add' -a '(__fish_zpool_complete_vdevs)'
# attach completions
complete -c zpool -f -n '__fish_zpool_using_command attach' -s f -d 'Force use of virtual device'
if test $OS = 'Linux'
complete -c zpool -x -n '__fish_zpool_using_command attach' -s o -d 'Pool property' -a '(__fish_zpool_list_device_properties)'
end
complete -c zpool -x -n '__fish_zpool_using_command attach' -d 'Pool to attach virtual device to' -a '(__fish_complete_zfs_pools)'
complete -c zpool -x -n '__fish_zpool_using_command attach' -d 'Virtual device to operate on' -a '(__fish_zpool_list_available_vdevs)'
# clear completions
if test $OS = 'FreeBSD'
complete -c zpool -f -n '__fish_zpool_using_command clear' -s F -d 'Initiate recovery mode'
complete -c zpool -f -n '__fish_zpool_using_command clear; and __fish_contains_opt -s F' -s n -d 'Dry run: only determine if the recovery is possible, without attempting it'
end
complete -c zpool -x -n '__fish_zpool_using_command clear' -d 'Pool to clear errors on' -a '(__fish_complete_zfs_pools)'
complete -c zpool -f -n '__fish_zpool_using_command clear' -d 'Virtual device to operate on' -a '(__fish_zpool_list_used_vdevs)'
# create completions
if test $OS = 'SunOS'
complete -c zpool -f -n '__fish_zpool_using_command create' -s B -d 'Create whole disk pool with EFI System partition to support booting system with UEFI firmware'
else
complete -c zpool -f -n '__fish_zpool_using_command create' -s f -d 'Force use of virtual device'
end
complete -c zpool -f -n '__fish_zpool_using_command create' -s n -d 'Dry run, only display resulting configuration'
complete -c zpool -f -n '__fish_zpool_using_command create' -s d -d 'Do not enable any feature on the new pool'
complete -c zpool -x -n '__fish_zpool_using_command create' -s o -d 'Pool property' -a '(__fish_zpool_list_writeonce_properties; __fish_zpool_list_rw_properties)'
complete -c zpool -x -n '__fish_zpool_using_command create' -s O -d 'Root filesystem property' -a '(__fish_complete_zfs_ro_properties; __fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties)'
complete -c zpool -r -n '__fish_zpool_using_command create' -s R -d 'Equivalent to "-o cachefile=none,altroot=ROOT"'
complete -c zpool -x -n '__fish_zpool_using_command create' -s m -d 'Root filesystem mountpoint' -a 'legacy none'
if test $OS = 'Linux'
complete -c zpool -x -n '__fish_zpool_using_command create' -s t -d 'Set a different in-core pool name'
end
complete -c zpool -x -n '__fish_zpool_using_command create' -d 'Virtual device to add' -a '(__fish_zpool_complete_vdevs)'
# destroy completions
complete -c zpool -f -n '__fish_zpool_using_command destroy' -s f -d 'Force unmounting of all contained datasets'
complete -c zpool -x -n '__fish_zpool_using_command destroy' -d 'Pool to destroy' -a '(__fish_complete_zfs_pools)'
# detach completions
complete -c zpool -x -n '__fish_zpool_using_command clear' -d 'Pool to detach device from' -a '(__fish_complete_zfs_pools)'
complete -c zpool -x -n '__fish_zpool_using_command clear' -d 'Physical device to detach' -a '(__fish_zpool_list_used_vdevs)'
# events completions
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_using_command events' -s v -d 'Print verbose event information'
complete -c zpool -f -n '__fish_zpool_using_command events' -s H -d 'Print output in a machine-parsable format'
complete -c zpool -f -n '__fish_zpool_using_command events' -s f -d 'Output appended data as the log grows'
complete -c zpool -f -n '__fish_zpool_using_command events' -s c -d 'Clear all previous events'
complete -c zpool -f -n '__fish_zpool_using_command events' -d 'Pool to read events from' -a '(__fish_complete_zfs_pools)'
end
# export completions
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_using_command export' -s a -d 'Export all pools'
end
complete -c zpool -f -n '__fish_zpool_using_command export' -s f -d 'Force unmounting of all contained datasets'
complete -c zpool -x -n '__fish_zpool_using_command export' -d 'Pool to export' -a '(__fish_complete_zfs_pools)'
# get completions
complete -c zpool -f -n '__fish_zpool_using_command get' -s p -d 'Print parsable (exact) values for numbers'
complete -c zpool -f -n '__fish_zpool_using_command get' -s H -d 'Print output in a machine-parsable format'
if contains -- $OS FreeBSD SunOS
complete -c zpool -x -n '__fish_zpool_using_command get' -s o -d 'Fields to display' -a '(__fish_zpool_append (__fish_zpool_list_get_fields))'
end
complete -c zpool -x -n '__fish_zpool_using_command get' -d 'Properties to get' -a '(__fish_zpool_append (__fish_zpool_list_importtime_properties; __fish_zpool_list_rw_properties; __fish_zpool_list_writeonce_properties; __fish_zpool_list_ro_properties; __fish_zpool_list_device_properties; echo -e "all\t"(_ "All properties")))'
complete -c zpool -x -n '__fish_zpool_using_command get' -d 'Pool to get properties of' -a '(__fish_complete_zfs_pools)'
# history completions
complete -c zpool -f -n '__fish_zpool_using_command history' -s i -d 'Also display internal events'
complete -c zpool -f -n '__fish_zpool_using_command history' -s l -d 'Display log records using long format'
complete -c zpool -f -n '__fish_zpool_using_command history' -d 'Pool to get command history of' -a '(__fish_complete_zfs_pools)'
# import completions
complete -c zpool -r -n '__fish_zpool_using_command import; and __fish_not_contain_opt -s d' -s c -d 'Read configuration from specified cache file'
complete -c zpool -r -n '__fish_zpool_using_command import; and __fish_not_contain_opt -s c' -s d -d 'Search for devices or files in specified directory'
complete -c zpool -f -n '__fish_zpool_using_command import' -s D -d 'List or import destroyed pools only (requires -f for importation)'
complete -c zpool -x -n '__fish_zpool_using_command import' -s o -d 'Mount properties for contained datasets' -a '(__fish_zpool_append (__fish_complete_zfs_mountpoint_properties))'
complete -c zpool -x -n '__fish_zpool_using_command import' -s o -d 'Properties of the imported pool' -a '(__fish_complete_zfs_mountpoint_properties; __fish_zpool_list_importtime_properties; __fish_zpool_list_rw_properties)'
complete -c zpool -f -n '__fish_zpool_using_command import' -s f -d 'Force import'
complete -c zpool -f -n '__fish_zpool_using_command import' -s F -d 'Recovery mode'
complete -c zpool -f -n '__fish_zpool_using_command import' -s a -d 'Search for and import all pools found'
complete -c zpool -f -n '__fish_zpool_using_command import' -s m -d 'Ignore missing log device (risk of loss of last changes)'
complete -c zpool -r -n '__fish_zpool_using_command import' -s R -d 'Equivalent to "-o cachefile=none,altroot=ROOT"'
complete -c zpool -f -n '__fish_zpool_using_command import' -s N -d 'Do not mount contained filesystems'
complete -c zpool -f -n '__fish_zpool_using_command import; and __fish_contains_opt -s F' -s n -d 'Dry run: only determine if the recovery is possible, without attempting it'
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_using_command import; and __fish_contains_opt -s F' -s X -d 'Roll back to a previous TXG (hazardous)'
complete -c zpool -r -n '__fish_zpool_using_command import' -s T -d 'TXG to roll back to (implies -FX)'
complete -c zpool -f -n '__fish_zpool_using_command import' -s t -d 'Specify, as the last argument, a temporary pool name'
end
complete -c zpool -f -n '__fish_zpool_using_command import; and __fish_not_contain_opt -s a' -d 'Pool to import' -a '(__fish_complete_zfs_pools)'
# iostat completions
complete -c zpool -x -n '__fish_zpool_using_command iostat' -s T -d 'Display a timestamp using specified format'
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_using_command iostat' -s g -d 'Display virtual device GUID instead of device name'
complete -c zpool -f -n '__fish_zpool_using_command iostat' -s L -d 'Resolve device path symbolic links'
complete -c zpool -f -n '__fish_zpool_using_command iostat' -s P -d 'Display device full path'
complete -c zpool -f -n '__fish_zpool_using_command iostat' -s y -d 'Omit statistics since boot'
end
complete -c zpool -f -n '__fish_zpool_using_command iostat' -s v -d 'Print verbose statistics'
complete -c zpool -f -n '__fish_zpool_using_command iostat' -d 'Pool to retrieve I/O stats from' -a '(__fish_complete_zfs_pools)'
# labelclear completions
complete -c zpool -f -n '__fish_zpool_using_command labelclear' -s f -d 'Treat exported or foreign devices as inactive'
complete -c zpool -x -n '__fish_zpool_using_command labelclear' -d 'Device to clear ZFS label information from' -a '(__fish_zpool_list_available_vdevs)'
# list completions
complete -c zpool -f -n '__fish_zpool_using_command list' -s H -d 'Print output in a machine-parsable format'
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_using_command list' -s g -d 'Display virtual device GUID instead of device name'
complete -c zpool -f -n '__fish_zpool_using_command list' -s L -d 'Resolve device path symbolic links'
end
complete -c zpool -f -n '__fish_zpool_using_command list' -s P -d 'Display device full path'
complete -c zpool -x -n '__fish_zpool_using_command list' -s T -d 'Display a timestamp using specified format'
complete -c zpool -f -n '__fish_zpool_using_command list' -s v -d 'Print verbose statistics'
complete -c zpool -x -n '__fish_zpool_using_command list' -s o -d 'Property to list' -a '(__fish_zpool_append (__fish_zpool_list_importtime_properties; __fish_zpool_list_rw_properties; __fish_zpool_list_writeonce_properties; __fish_zpool_list_ro_properties; __fish_zpool_list_device_properties))'
complete -c zpool -f -n '__fish_zpool_using_command list' -d 'Pool to list properties of' -a '(__fish_complete_zfs_pools)'
# offline completions
complete -c zpool -f -n '__fish_zpool_using_command offline' -s t -d 'Temporarily offline'
complete -c zpool -x -n '__fish_zpool_using_command offline' -d 'Pool to offline device from' -a '(__fish_complete_zfs_pools)'
complete -c zpool -x -n '__fish_zpool_using_command offline' -d 'Physical device to offline' -a '(__fish_zpool_list_used_vdevs)'
# online completions
complete -c zpool -f -n '__fish_zpool_using_command online' -s e -d 'Expand the device to use all available space'
complete -c zpool -x -n '__fish_zpool_using_command online' -d 'Pool to bring device back online on' -a '(__fish_complete_zfs_pools)'
complete -c zpool -x -n '__fish_zpool_using_command online' -d 'Physical device to bring back online' -a '(__fish_zpool_list_used_vdevs)'
# reguid completions
complete -c zpool -x -n '__fish_zpool_using_command reguid' -d 'Pool which GUID is to be changed' -a '(__fish_complete_zfs_pools)'
# remove completions
complete -c zpool -x -n '__fish_zpool_using_command remove' -d 'Pool to remove device from' -a '(__fish_complete_zfs_pools)'
complete -c zpool -x -n '__fish_zpool_using_command remove' -d 'Physical device to remove' -a '(__fish_zpool_list_used_vdevs)'
# reopen completions
complete -c zpool -x -n '__fish_zpool_using_command reopen' -d 'Pool which devices are to be reopened' -a '(__fish_complete_zfs_pools)'
# replace completions
complete -c zpool -f -n '__fish_zpool_using_command replace' -s f -d 'Force use of virtual device'
if test $OS = 'Linux'
complete -c zpool -x -n '__fish_zpool_using_command replace' -s o -d 'Pool property' -a '(__fish_zpool_list_device_properties)'
end
complete -c zpool -x -n '__fish_zpool_using_command replace' -d 'Pool to replace device' -a '(__fish_complete_zfs_pools)'
complete -c zpool -x -n '__fish_zpool_using_command replace' -d 'Pool device to be replaced' -a '(__fish_zpool_list_used_vdevs)'
complete -c zpool -f -n '__fish_zpool_using_command replace' -d 'Device to use for replacement' -a '(__fish_zpool_list_available_vdevs)'
# scrub completions
complete -c zpool -f -n '__fish_zpool_using_command scrub' -s s -d 'Stop scrubbing'
if test $OS = 'SunOS'
complete -c zpool -f -n '__fish_zpool_using_command scrub' -s p -d 'Pause scrubbing'
end
complete -c zpool -x -n '__fish_zpool_using_command scrub' -d 'Pool to start/stop scrubbing' -a '(__fish_complete_zfs_pools)'
# set completions
complete -c zpool -x -n '__fish_zpool_using_command set' -d 'Property to set' -a '(__fish_zpool_list_rw_properties)'
complete -c zpool -x -n '__fish_zpool_using_command set' -d 'Pool which property is to be set' -a '(__fish_complete_zfs_pools)'
# split completions
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_using_command split' -s g -d 'Display virtual device GUID instead of device name'
complete -c zpool -f -n '__fish_zpool_using_command split' -s L -d 'Resolve device path symbolic links'
complete -c zpool -f -n '__fish_zpool_using_command split' -s P -d 'Display device full path'
end
complete -c zpool -f -n '__fish_zpool_using_command split' -s n -d 'Dry run: only display resulting configuration'
complete -c zpool -r -n '__fish_zpool_using_command split' -s R -d 'Set altroot for newpool and automatically import it'
complete -c zpool -x -n '__fish_zpool_using_command split' -s o -d 'Pool property' -a '(__fish_zpool_list_writeonce_properties; __fish_zpool_list_rw_properties)'
if test $OS = 'FreeBSD'
complete -c zpool -x -n '__fish_zpool_using_command split; and __fish_contains_opt -s R' -s o -d 'Mount properties for contained datasets' -a '(__fish_zpool_append (__fish_complete_zfs_mountpoint_properties))'
end
complete -c zpool -x -n '__fish_zpool_using_command split' -d 'Pool to split' -a '(__fish_complete_zfs_pools)'
# status completions
if test $OS = 'Linux'
complete -c zpool -f -n '__fish_zpool_using_command status' -s g -d 'Display virtual device GUID instead of device name'
complete -c zpool -f -n '__fish_zpool_using_command status' -s L -d 'Resolve device path symbolic links'
complete -c zpool -f -n '__fish_zpool_using_command status' -s P -d 'Display device full path'
complete -c zpool -f -n '__fish_zpool_using_command status' -s D -d 'Display deduplication histogram'
else if test $OS = 'SunOS'
complete -c zpool -f -n '__fish_zpool_using_command status' -s D -d 'Display deduplication histogram'
end
complete -c zpool -f -n '__fish_zpool_using_command status' -s v -d 'Verbose mode'
complete -c zpool -f -n '__fish_zpool_using_command status' -s x -d 'Only display status for unhealthy or unavailable pools'
complete -c zpool -x -n '__fish_zpool_using_command status' -s T -d 'Display a timestamp using specified format'
complete -c zpool -f -n '__fish_zpool_using_command status' -d 'Pool which status is to be displayed' -a '(__fish_complete_zfs_pools)'
# upgrade completions
complete -c zpool -f -n '__fish_zpool_using_command upgrade' -s a -d 'Upgrade all eligible pools, enabling all supported features'
complete -c zpool -f -n '__fish_zpool_using_command upgrade' -s v -d 'Display upgradeable ZFS versions'
complete -c zpool -x -n '__fish_zpool_using_command upgrade' -s V -d 'Upgrade to the specified legacy version'
complete -c zpool -f -n '__fish_zpool_using_command upgrade; and __fish_not_contain_opt -s a' -d 'Pool which status is to be displayed' -a '(__fish_complete_zfs_pools)'

View file

@ -0,0 +1,29 @@
function __fish_complete_zfs_mountpoint_properties -d "Completes with ZFS mountpoint properties"
set -l OS ""
switch (uname)
case Linux
set OS "Linux"
case Darwin
set OS "macOS"
case FreeBSD
set OS "FreeBSD"
case SunOS
set OS "SunOS"
# Others?
case "*"
set OS "unknown"
end
echo -e "atime\t"(_ "Update access time on read")" (on, off)"
echo -e "devices\t"(_ "Are contained device nodes openable")" (on, off)"
echo -e "exec\t"(_ "Can contained executables be executed")" (on, off)"
echo -e "readonly\t"(_ "Read-only")" (on, off)"
echo -e "setuid\t"(_ "Respect set-UID bit")" (on, off)"
if test $OS = "SunOS"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
else if test $OS = "Linux"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "relatime\t"(_ "Sometimes update access time on read")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
end
end

View file

@ -0,0 +1,3 @@
function __fish_complete_zfs_pools -d "Completes with available ZFS pools"
zpool list -o name,comment -H | string replace -a \t'-' ''
end

View file

@ -0,0 +1,46 @@
function __fish_complete_zfs_ro_properties -d "Completes with ZFS read-only properties"
echo -e "available\t"(_ "Available space")
echo -e "avail\t"(_ "Available space")
echo -e "compressratio\t"(_ "Achieved compression ratio")
echo -e "creation\t"(_ "Dataset creation time")
echo -e "clones\t"(_ "Snapshot clones")
echo -e "defer_destroy\t"(_ "Marked for deferred destruction")
echo -e "filesystem_count\t"(_ "Total lower-level filesystems and volumes")
echo -e "logicalreferenced\t"(_ "Logical total space")
echo -e "lrefer\t"(_ "Logical total space")
echo -e "logicalused\t"(_ "Logical used space")
echo -e "lused\t"(_ "Logical used space")
echo -e "mounted\t"(_ "Is currently mounted?")
echo -e "origin\t"(_ "Source snapshot")
if __fish_is_zfs_feature_enabled "feature@extensible_dataset"
echo -e "receive_resume_token\t"(_ "Token for interrupted reception resumption")
end
echo -e "referenced\t"(_ "Total space")
echo -e "refer\t"(_ "Total space")
echo -e "refcompressratio\t"(_ "Achieved compression ratio of referenced space")
echo -e "snapshot_count\t"(_ "Total lower-level snapshots")
echo -e "type\t"(_ "Dataset type")
echo -e "used\t"(_ "Space used by dataset and children")
echo -e "usedbychildren\t"(_ "Space used by children datasets")
echo -e "usedbydataset\t"(_ "Space used by dataset itself")
echo -e "usedbyrefreservation\t"(_ "Space used by refreservation")
echo -e "usedbysnapshots\t"(_ "Space used by dataset snapshots")
echo -e "userrefs\t"(_ "Holds count")
echo -e "volblocksize\t"(_ "Volume block size")
echo -e "written\t"(_ "Referenced data written since previous snapshot")
# Autogenerate userused@$USER list; only usernames are supported by the completion, but the zfs command supports more formats
for user in (__fish_print_users)
set -l tabAndBefore (echo -e "userused@$user\t")
printf (_ "%sDataset space use by user %s\n") $tabAndBefore $user
end
# Autogenerate groupused@$USER list
for group in (__fish_print_groups)
set -l tabAndBefore (echo -e "groupused@$group\t")
printf (_ "%sDataset space use by group %s\n") $tabAndBefore $group
end
# Autogenerate written@$SNAPSHOT list
for snapshot in (__fish_print_zfs_snapshots)
set -l tabAndBefore (echo -e "written@$snapshot\t")
printf (_ "%sReferenced data written since snapshot %s\n") $tabAndBefore $snapshot
end
end

View file

@ -0,0 +1,97 @@
function __fish_complete_zfs_rw_properties -d "Completes with ZFS read-write properties"
set -l OS ""
switch (uname)
case Linux
set OS "Linux"
case Darwin
set OS "macOS"
case FreeBSD
set OS "FreeBSD"
case SunOS
set OS "SunOS"
# Others?
case "*"
set OS "unknown"
end
echo -e "aclinherit\t"(_ "Inheritance of ACL entries")" (discard, noallow, restricted, passthrough, passthrough-x)"
echo -e "atime\t"(_ "Update access time on read")" (on, off)"
echo -e "canmount\t"(_ "Is the dataset mountable")" (on, off, noauto)"
set -l additional_algs ''
if contains -- $OS FreeBSD SunOS
set additional_algs "$additional_algs, noparity"
end
if __fish_is_zfs_feature_enabled "feature@sha512"
set additional_algs "$additional_algs, sha512"
end
if __fish_is_zfs_feature_enabled "feature@skein"
set additional_algs "$additional_algs, skein"
end
if __fish_is_zfs_feature_enabled "feature@edonr"
set additional_algs "$additional_algs, edonr"
end
echo -e "checksum\t"(_ "Data checksum")" (on, off, fletcher2, fletcher4, sha256$additional_algs)"
if __fish_is_zfs_feature_enabled "feature@lz4_compress"
set additional_algs ", lz4"
end
echo -e "compression\t"(_ "Compression algorithm")" (on, off, lzjb$additional_algs, gzip, gzip-[1-9], zle)"
set -e additional_algs
echo -e "copies\t"(_ "Number of copies of data")" (1, 2, 3)"
echo -e "dedup\t"(_ "Deduplication")" (on, off, verify, sha256[,verify])"
echo -e "devices\t"(_ "Are contained device nodes openable")" (on, off)"
echo -e "exec\t"(_ "Can contained executables be executed")" (on, off)"
echo -e "filesystem_limit\t"(_ "Max number of filesystems and volumes")" (COUNT, none)"
echo -e "mountpoint\t"(_ "Mountpoint")" (PATH, none, legacy)"
echo -e "primarycache\t"(_ "Which data to cache in ARC")" (all, none, metadata)"
echo -e "quota\t"(_ "Max size of dataset and children")" (SIZE, none)"
echo -e "snapshot_limit\t"(_ "Max number of snapshots")" (COUNT, none)"
echo -e "readonly\t"(_ "Read-only")" (on, off)"
echo -e "recordsize\t"(_ "Suggest block size")" (SIZE)"
echo -e "redundant_metadata\t"(_ "How redundant are the metadata")" (all, most)"
echo -e "refquota\t"(_ "Max space used by dataset itself")" (SIZE, none)"
echo -e "refreservation\t"(_ "Min space guaranteed to dataset itself")" (SIZE, none)"
echo -e "reservation\t"(_ "Min space guaranteed to dataset")" (SIZE, none)"
echo -e "secondarycache\t"(_ "Which data to cache in L2ARC")" (all, none, metadata)"
echo -e "setuid\t"(_ "Respect set-UID bit")" (on, off)"
echo -e "sharenfs\t"(_ "Share in NFS")" (on, off, OPTS)"
echo -e "logbias\t"(_ "Hint for handling of synchronous requests")" (latency, throughput)"
echo -e "snapdir\t"(_ "Hide .zfs directory")" (hidden, visible)"
echo -e "sync\t"(_ "Handle of synchronous requests")" (standard, always, disabled)"
echo -e "volsize\t"(_ "Volume logical size")" (SIZE)"
# Autogenerate userquota@$USER list; only usernames are supported by the completion, but the zfs command supports more formats
for user in (__fish_print_users)
set -l tabAndBefore (echo -e "userquota@$user\t")
printf (_ "%sMax usage by user %s\n") $tabAndBefore $user
end
# Autogenerate groupquota@$USER list
for group in (__fish_print_groups)
set -l tabAndBefore (echo -e "groupquota@$group\t")
printf (_ "%sMax usage by group %s\n") $tabAndBefore $group
end
if test $OS = "SunOS"
echo -e "aclmode\t"(_ "How is ACL modified by chmod")" (discard, groupmask, passthrough, restricted)"
echo -e "mlslabel\t"(_ "Can the dataset be mounted in a zone with Trusted Extensions enabled")" (LABEL, none)"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "sharesmb\t"(_ "Share in Samba")" (on, off)"
echo -e "shareiscsi\t"(_ "Share as an iSCSI target")" (on, off)"
echo -e "version\t"(_ "On-disk version of filesystem")" (1, 2, current)"
echo -e "vscan\t"(_ "Scan regular files for viruses on opening and closing")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
echo -e "zoned\t"(_ "Managed from a non-global zone")" (on, off)"
else if test $OS = "Linux"
echo -e "acltype\t"(_ "Use no ACL or POSIX ACL")" (noacl, posixacl)"
echo -e "nbmand\t"(_ "Mount with Non Blocking mandatory locks")" (on, off)"
echo -e "relatime\t"(_ "Sometimes update access time on read")" (on, off)"
echo -e "shareiscsi\t"(_ "Share as an iSCSI target")" (on, off)"
echo -e "sharesmb\t"(_ "Share in Samba")" (on, off)"
echo -e "snapdev\t"(_ "Hide volume snapshots")" (hidden, visible)"
echo -e "version\t"(_ "On-disk version of filesystem")" (1, 2, current)"
echo -e "vscan\t"(_ "Scan regular files for viruses on opening and closing")" (on, off)"
echo -e "xattr\t"(_ "Extended attributes")" (on, off, sa)"
else if test $OS = "FreeBSD"
echo -e "aclmode\t"(_ "How is ACL modified by chmod")" (discard, groupmask, passthrough, restricted)"
echo -e "volmode\t"(_ "How to expose volumes to OS")" (default, geom, dev, none)"
end
# User properties; the /dev/null redirection masks the possible "no datasets available"
zfs list -o all ^/dev/null | head -n 1 | string replace -a -r "\s+" "\n" | string match -e ":" | string lower
end

View file

@ -0,0 +1,30 @@
function __fish_complete_zfs_write_once_properties -d "Completes with ZFS properties which can only be written at filesystem creation, and only be read thereafter"
set -l OS ""
switch (uname)
case Linux
set OS "Linux"
case Darwin
set OS "macOS"
case FreeBSD
set OS "FreeBSD"
case SunOS
set OS "SunOS"
# Others?
case "*"
set OS "unknown"
end
echo -e "normalization\t"(_ "Unicode normalization")" (none, formC, formD, formKC, formKD)"
echo -e "utf8only\t"(_ "Reject non-UTF-8-compliant filenames")" (on, off)"
if test $OS = "Linux"
echo -e "overlay\t"(_ "Allow overlay mount")" (on, off)"
if command -sq sestatus # SELinux is enabled
echo -e "context\t"(_ "SELinux context for the child filesystem")
echo -e "fscontext\t"(_ "SELinux context for the filesystem being mounted")
echo -e "defcontext\t"(_ "SELinux context for unlabeled files")
echo -e "rootcontext\t"(_ "SELinux context for the root inode of the filesystem")
end
echo -e "casesensitivity\t"(_ "Case sensitivity")" (sensitive, insensitive)"
else
echo -e "casesensitivity\t"(_ "Case sensitivity")" (sensitive, insensitive, mixed)"
end
end

View file

@ -0,0 +1,16 @@
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"
set -l pool (string replace -r '/.*' '' -- $target)
set -l feature_name ""
if test -z "$pool"
set feature_name (zpool get all -H | string match -r "\s$feature\s")
else
set feature_name (zpool get all -H $pool | string match -r "$pool\s$feature\s")
end
if test $status -ne 0 # No such feature
return 1
end
echo $feature_name | read -l _ _ state _
set -l state (echo $feature_name | cut -f3)
string match -qr '(active|enabled)' -- $state
return $status
end

View file

@ -0,0 +1,7 @@
# This should be used where you want group names without a description. If you also want
# a description, such as when getting a list of groups for a completion, you probably want
# __fish_complete_groups.
function __fish_print_groups --description "Print a list of local groups"
# Leave the heavy lifting to __fish_complete_groups but strip the descriptions.
__fish_complete_groups | string replace -r '^([^\t]*)\t.*' '$1'
end

View file

@ -0,0 +1,5 @@
function __fish_print_zfs_bookmarks -d "Lists ZFS bookmarks, if the feature is enabled"
if __fish_is_zfs_feature_enabled 'feature@bookmarks'
zfs list -t bookmark -o name -H
end
end

View file

@ -0,0 +1,3 @@
function __fish_print_zfs_filesystems -d "Lists ZFS filesystems"
zfs list -t filesystem -o name -H
end

View file

@ -0,0 +1,3 @@
function __fish_print_zfs_snapshots -d "Lists ZFS snapshots"
zfs list -t snapshot -o name -H
end

View file

@ -0,0 +1,3 @@
function __fish_print_zfs_volumes -d "Lists ZFS volumes"
zfs list -t volume -o name -H
end