fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
0df6fa791
master
1# Fish completions for the ZFS `zfs` command 2# 3# Possible enhancements: 4# - Add a test to propose iSCSI and Trusted Extensions completions only when such system is present; 5# - Illumos man pages suggests that it does not support nbmand nor atime mount option, so these 6# properties should be proposed only when available; 7# - Generally, propose properties only when the current OS and ZFS versions support them; 8# - For the promote command, propose only eligible filesystems; 9# - For the rollback command, propose only the most recent snapshot for each dataset, as it will not 10# accept an intermediary snapshot; 11# - For the release command, complete with existing tags; 12# - For the diff command, complete the destination dataset of the diff; 13# - For the program command, complete the script to be executed; 14# - For commands accepting several arguments of different types, propose arguments in the right 15# order: for get, once the ZFS parameters have been given, only propose datasets. 16 17set -l OS"" 18set -l freebsd_version"" 19switch ( uname ) 20case Linux 21set OS Linux 22case Darwin 23set OS macOS 24case FreeBSD 25set OS FreeBSD 26set freebsd_version( uname -U) 27case SunOS 28set OS SunOS 29# Others? 30case "*" 31set OS unknown 32end 33 34# Certain functionality is exclusive to platforms using OpenZFS. This used to be just Linux, but it 35# now includes FreeBSD 13 and above. 36if not type -q __fish_is_openzfs 37function __fish_is_openzfs --inherit-variable freebsd_version --inherit-variable OS 38test $OS = Linux|| test $OS = FreeBSD-a $freebsd_version -gt 1300000 39end 40end 41 42# Does the current invocation need a command? 43function __fish_zfs_needs_command 44set -l bookmark"" 45if __fish_is_zfs_feature_enabled "feature@bookmarks" 46set bookmark bookmark 47end 48 49not __fish_seen_subcommand_from \? create destroy snap{, shot} rollback clone promote rename list set get inherit upgrade{ user, group} space{ u, un,} mount{ un,} share$bookmark send receive recv{ un,} allow hold{ s,} release diff program load-key unload-key change-key 50end 51 52function __fish_zfs_using_command # ZFS command whose completions are looked for 53set -l cmd( commandline -xpc) 54if test ( count $cmd ) -eq 1 # The token can only be 'zfs', so skip 55return 2 56end 57if test $cmd [ 2 ] = $argv 58return 0 59else 60return 1 61end 62end 63 64function __fish_zfs_list_dataset_types 65echo -e"filesystem\tZFS filesystem" 66echo -e"snapshot\tZFS filesystem snapshot" 67echo -e"volume\tZFS block storage device" 68echo -e"bookmark\tZFS snapshot bookmark" 69echo -e"all\tAny ZFS dataset" 70end 71 72function __fish_zfs_list_source_types 73echo -e"local\tDataset-specific value" 74echo -e"default\tDefault ZFS value" 75echo -e"inherited\tValue inherited from parent dataset" 76echo -e"received\tValue received by 'zfs receive'" 77echo -e"temporary\tValue valid for the current mount" 78echo -e"none\tRead-only value" 79end 80 81function __fish_zfs_list_get_fields 82echo -e"name\tDataset full name" 83echo -e"property\tProperty" 84echo -e"value\tProperty value" 85echo -e"source\tProperty value origin" 86end 87 88function __fish_zfs_list_space_fields 89echo -e"type\tIdentity type" 90echo -e"name\tIdentity name" 91echo -e"used\tSpace usage" 92echo -e"quota\tSpace quota" 93end 94 95function __fish_zfs_list_userspace_types 96echo -e"posixuser\tPOSIX user" 97echo -e"smbuser\tSamba user" 98echo -e"all\tBoth types" 99end 100 101function __fish_zfs_list_groupspace_types 102echo -e"posixgroup\tPOSIX group" 103echo -e"smbgroup\tSamba group" 104echo -e"all\tBoth types" 105end 106 107function __fish_zfs_complete_property_values -a name 108# To make updates easier, instead of using a switch/case here we just copy-and-paste the lines 109# from zfsprops(8) directly, and then parse them when the function is called. 110 111set all_options" 112aclinherit=discard|noallow|restricted|passthrough|passthrough-x 113aclmode=discard|groupmask|passthrough|restricted 114acltype=off|nfsv4|posix 115atime=on|off 116canmount=on|off|noauto 117checksum=on|off|fletcher2|fletcher4|sha256|noparity|sha512|skein|edonr 118compression=on|off|gzip|gzip-N|lz4|lzjb|zle|zstd|zstd-N|zstd-fast|zstd-fast-N 119context=none|SELinux_User:SElinux_Role:Selinux_Type:Sensitivity_Level 120fscontext=none|SELinux_User:SElinux_Role:Selinux_Type:Sensitivity_Level 121defcontext=none|SELinux_User:SElinux_Role:Selinux_Type:Sensitivity_Level 122rootcontext=none|SELinux_User:SElinux_Role:Selinux_Type:Sensitivity_Level 123copies=1|2|3 124devices=on|off 125dedup=off|on|verify|sha256[,verify]|sha512[,verify]|skein[,verify]|edonr,verify 126dnodesize=legacy|auto|1k|2k|4k|8k|16k 127encryption=off|on|aes-128-ccm|aes-192-ccm|aes-256-ccm|aes-128-gcm|aes-192-gcm|aes-256-gcm 128keyformat=raw|hex|passphrase 129keylocation=prompt|file://</absolute/file/path> 130pbkdf2iters=iterations 131exec=on|off 132filesystem_limit=count|none 133special_small_blocks=size 134mountpoint=path|none|legacy 135nbmand=on|off 136overlay=on|off 137primarycache=all|none|metadata 138quota=size|none 139snapshot_limit=count|none 140recordsize=size 141readonly=on|off 142redundant_metadata=all|most 143refquota=size|none 144refreservation=size|none|auto 145relatime=on|off 146reservation=size|none 147secondarycache=all|none|metadata 148setuid=on|off 149sharesmb=on|off|opts 150sharenfs=on|off|opts 151logbias=latency|throughput 152snapdev=hidden|visible 153snapdir=hidden|visible 154sync=standard|always|disabled 155version=N|current 156volsize=size 157volmode=default | full | geom | dev | none 158vscan=on|off 159xattr=on|off|sa 160jailed=off | on 161casesensitivity=sensitive|insensitive|mixed 162normalization=none|formC|formD|formKC|formKD 163utf8only=on|off 164keyformat=raw|passphrase|hex 165keylocation=stdin|file:/// 166encryption=off|on|aes-128-ccm|aes-192-ccm|aes-256-ccm|aes-128-gcm|aes-192-gcm|aes-256-gcm 167" 168# Convert the list above into an array of strings 169set all_options( string split\n --$all_options | string trim) 170 171# Make sure the name doesn't already have a trailing = (depending on the context) 172set name( string match -r'^[^=]+' --$name ) 173# Extract the values "value1|value2" from the long list of "key=value1|value2" 174set options( string match" $name =*" --$all_options | string split =)[ 2 ] 175# echo o1: (string escape -- $options) 176# Put each possible value on its own line and account for formatting disparities 177set options( string replace -a'|' \n --$options | string trim) 178# echo o2: (string escape -- $options) 179# Remove open-ended options (size, count, path) 180set options( string match -rv'^(size|count|iterations|path)$|\<.*?\>' --$options ) 181# echo o3: (string escape -- $options) 182# Expand optionally comma-separated arguments (e.g. skein[,verify] => skein\nskein,verify) 183set options( string replace -r"(.*)\[,(.*?)\]" '$1\n$1,$2' --$options ) 184# echo o4: (string escape -- $options) 185 186if set -q options[ 1 ] 187printf " $name =%s\n" $options 188end 189end 190 191# Generate a list of possible values from the man page. 192# NB: This includes "hints" like "size" or "opts" which may be useful or unwanted. *shrug* 193if type -q man&& type -q col 194function __fish_zfs_property_options 195set -l property( string escape --style=regex --$argv [ 1 ]) 196set -l values( command man zfs| col -b| string replace -rf --'^\s*' $property '=(.*\|.*)' '$1' | string split' | ' ) 197printf '%s\n' $property =$values 198end 199else 200function __fish_zfs_property_options 201end 202end 203 204function __fish_zfs_list_permissions -V OS 205echo -e"allow\tAlso needs the permission to be allowed" 206echo -e"clone\tAlso needs the 'create' and 'mount' permissions in the origin filesystem" 207echo -e"create\tAlso needs the 'mount' permission" 208echo -e"destroy\tAlso needs the 'mount' permission" 209echo -e mount 210echo -e"promote\tAlso needs the 'promote' and 'mount' permissions in the origin filesystem" 211echo -e"receive\tAlso needs the 'create' and 'mount' permissions" 212echo -e"rename\tAlso needs the 'create' and 'mount' permissions in the new parent" 213echo -e"rollback\tAlso needs the 'mount' permission" 214echo -e send 215echo -e"share\tFor SMB and NFS shares" 216echo -e"snapshot\tAlso needs the 'mount' permission" 217echo -e groupquota 218echo -e groupused 219echo -e"userprop\tAllows changing any user property" 220echo -e userquota 221echo -e userused 222# 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 223# RO properties 224echo -e"volblocksize\tVolume block size" 225# R/W properties 226echo -e"aclinherit\tInheritance of ACL entries (discard, noallow, restricted, passthrough, passthrough-x)" 227echo -e"atime\tUpdate access time on read (on, off)" 228echo -e"canmount\tIs the dataset mountable (on, off, noauto)" 229set -l additional_cksum_algs'' 230set -l additional_dedup_algs'' 231if contains --$OS FreeBSD SunOS 232set additional_cksum_algs", noparity" 233end 234if __fish_is_zfs_feature_enabled "feature@sha512" 235set additional_cksum_algs" $additional_cksum_algs , sha512" 236set additional_dedup_algs", sha512[,verify]" 237end 238if __fish_is_zfs_feature_enabled "feature@skein" 239set additional_cksum_algs" $additional_cksum_algs , skein" 240set additional_dedup_algs" $additional_dedup_algs , skein[,verify]" 241end 242if __fish_is_zfs_feature_enabled "feature@edonr" 243set additional_cksum_algs" $additional_cksum_algs , edonr" 244set additional_dedup_algs" $additional_dedup_algs , edonr[,verify]" 245end 246echo -e"checksum\tData checksum (on, off, fletcher2, fletcher4, sha256 $additional_cksum_algs )" 247set -e additional_cksum_algs 248set -l additional_compress_algs'' 249if __fish_is_zfs_feature_enabled "feature@lz4_compress" 250set additional_compress_algs", lz4" 251end 252echo -e"compression\tCompression algorithm (on, off, lzjb $additional_compress_algs , gzip, gzip-[1-9], zle)" 253set -e additional_compress_algs 254echo -e"copies\tNumber of copies of data (1, 2, 3)" 255echo -e"dedup\tDeduplication (on, off, verify, sha256[,verify] $additional_dedup_algs )" 256set -e additional_dedup_algs 257echo -e"devices\tAre contained device nodes openable (on, off)" 258echo -e"exec\tCan contained executables be executed (on, off)" 259echo -e"filesystem_limit\tMax number of filesystems and volumes (COUNT, none)" 260echo -e"mountpoint\tMountpoint (PATH, none, legacy)" 261echo -e"primarycache\tWhich data to cache in ARC (all, none, metadata)" 262echo -e"quota\tMax size of dataset and children (SIZE, none)" 263echo -e"snapshot_limit\tMax number of snapshots (COUNT, none)" 264echo -e"readonly\tRead-only (on, off)" 265echo -e"recordsize\tSuggest block size (SIZE)" 266echo -e"redundant_metadata\tHow redundant are the metadata (all, most)" 267echo -e"refquota\tMax space used by dataset itself (SIZE, none)" 268echo -e"refreservation\tMin space guaranteed to dataset itself (SIZE, none)" 269echo -e"reservation\tMin space guaranteed to dataset (SIZE, none)" 270echo -e"secondarycache\tWhich data to cache in L2ARC (all, none, metadata)" 271echo -e"setuid\tRespect set-UID bit (on, off)" 272echo -e"sharenfs\tShare in NFS (on, off, OPTS)" 273echo -e"logbias\tHint for handling of synchronous requests (latency, throughput)" 274echo -e"snapdir\tHide .zfs directory (hidden, visible)" 275echo -e"sync\tHandle of synchronous requests (standard, always, disabled)" 276echo -e"volsize\tVolume logical size (SIZE)" 277if test $OS = SunOS 278echo -e"zoned\tManaged from a non-global zone (on, off)" 279echo -e"mlslabel\tCan the dataset be mounted in a zone with Trusted Extensions enabled (LABEL, none)" 280echo -e"nbmand\tMount with Non Blocking mandatory locks (on, off)" 281echo -e"sharesmb\tShare in Samba (on, off)" 282echo -e"shareiscsi\tShare as an iSCSI target (on, off)" 283echo -e"version\tOn-disk version of filesystem (1, 2, current)" 284echo -e"vscan\tScan regular files for viruses on opening and closing (on, off)" 285echo -e"xattr\tExtended attributes (on, off, sa)" 286else if test $OS = Linux 287echo -e"acltype\tUse no ACL or POSIX ACL (noacl, posixacl)" 288echo -e"nbmand\tMount with Non Blocking mandatory locks (on, off)" 289echo -e"relatime\tSometimes update access time on read (on, off)" 290echo -e"shareiscsi\tShare as an iSCSI target (on, off)" 291echo -e"sharesmb\tShare in Samba (on, off)" 292echo -e"snapdev\tHide volume snapshots (hidden, visible)" 293echo -e"version\tOn-disk version of filesystem (1, 2, current)" 294echo -e"vscan\tScan regular files for viruses on opening and closing (on, off)" 295echo -e"xattr\tExtended attributes (on, off, sa)" 296else if test $OS = FreeBSD 297echo -e"aclmode\tHow is ACL modified by chmod (discard, groupmask, passthrough, restricted)" 298echo -e"volmode\tHow to expose volumes to OS (default, geom, dev, none)" 299end 300# Write-once properties 301echo -e"normalization\tUnicode normalization (none, formC, formD, formKC, formKD)" 302echo -e"utf8only\tReject non-UTF-8-compliant filenames (on, off)" 303if test $OS = Linux 304echo -e"casesensitivity\tCase sensitivity (sensitive, insensitive)" 305else # FreeBSD, SunOS and virtually all others 306echo -e"casesensitivity\tCase sensitivity (sensitive, insensitive, mixed)" 307end 308# Permissions set; if none are found, or if permission sets are not supported, no output is expected, even an error 309for iin ( zpool list -o name -H) 310zfs allow$i 311end | string match -r'@[[:alnum:]]*' | sort -u 312end 313 314function __fish_print_zfs_bookmarks -d"Lists ZFS bookmarks, if the feature is enabled" 315if __fish_is_zfs_feature_enabled 'feature@bookmarks' 316zfs list -t bookmark -o name -H 317end 318end 319 320function __fish_print_zfs_filesystems -d"Lists ZFS filesystems" 321zfs list -t filesystem -o name -H 322end 323 324function __fish_print_zfs_volumes -d"Lists ZFS volumes" 325zfs list -t volume -o name -H 326end 327 328complete -c zfs -f -n __fish_zfs_needs_command -s'?' -a'?' -d'Display a help message' 329complete -c zfs -f -n __fish_zfs_needs_command -a create -d'Create a volume or filesystem' 330complete -c zfs -f -n __fish_zfs_needs_command -a destroy -d'Destroy a dataset' 331complete -c zfs -f -n __fish_zfs_needs_command -a'snapshot snap' -d'Create a snapshot' 332complete -c zfs -f -n __fish_zfs_needs_command -a rollback -d'Roll back a filesystem to a previous snapshot' 333complete -c zfs -f -n __fish_zfs_needs_command -a clone -d'Create a clone of a snapshot' 334complete -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' 335complete -c zfs -f -n __fish_zfs_needs_command -a rename -d'Rename a dataset' 336complete -c zfs -f -n __fish_zfs_needs_command -a list -d'List dataset properties' 337complete -c zfs -f -n __fish_zfs_needs_command -a set -d'Set a dataset property' 338complete -c zfs -f -n __fish_zfs_needs_command -a get -d'Get one or several dataset properties' 339complete -c zfs -f -n __fish_zfs_needs_command -a inherit -d'Set a dataset property to be inherited' 340complete -c zfs -f -n __fish_zfs_needs_command -a upgrade -d'List upgradeable datasets, or upgrade one' 341complete -c zfs -f -n __fish_zfs_needs_command -a userspace -d'Get dataset space consumed by each user' 342complete -c zfs -f -n __fish_zfs_needs_command -a groupspace -d'Get dataset space consumed by each user group' 343complete -c zfs -f -n __fish_zfs_needs_command -a mount -d'Mount a filesystem' 344complete -c zfs -f -n __fish_zfs_needs_command -a'unmount umount' -d'Unmount a filesystem' 345complete -c zfs -f -n __fish_zfs_needs_command -a share -d'Share a given filesystem, or all of them' 346complete -c zfs -f -n __fish_zfs_needs_command -a unshare -d'Stop sharing a given filesystem, or all of them' 347if __fish_is_zfs_feature_enabled 'feature@bookmarks' 348complete -c zfs -f -n __fish_zfs_needs_command -a bookmark -d'Create a bookmark for a snapshot' 349end 350complete -c zfs -f -n __fish_zfs_needs_command -a send -d'Output a stream representation of a dataset' 351complete -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' 352complete -c zfs -f -n __fish_zfs_needs_command -a allow -d'Delegate, or display delegations of, rights on a dataset to (groups of) users' 353complete -c zfs -f -n __fish_zfs_needs_command -a unallow -d'Revoke delegations of rights on a dataset from (groups of) users' 354complete -c zfs -f -n __fish_zfs_needs_command -a hold -d'Put a named hold on a snapshot' 355complete -c zfs -f -n __fish_zfs_needs_command -a holds -d'List holds on a snapshot' 356complete -c zfs -f -n __fish_zfs_needs_command -a release -d'Remove a named hold from a snapshot' 357complete -c zfs -f -n __fish_zfs_needs_command -a diff -d'List changed files between a snapshot, and a filesystem or a previous snapshot' 358if test $OS = SunOS# This is currently only supported under Illumos, but that will probably change 359complete -c zfs -f -n __fish_zfs_needs_command -a program -d'Execute a ZFS Channel Program' 360end 361if __fish_is_openzfs 362complete -c zfs -f -n __fish_zfs_needs_command -a load-key -d"Load encryption key for dataset" 363complete -c zfs -f -n __fish_zfs_needs_command -a unload-key -d"Unload encryption key for dataset" 364complete -c zfs -f -n __fish_zfs_needs_command -a change-key -d"Change wrapper encryption key for dataset" 365end 366 367# Completions hereafter try to follow the man pages commands order, for maintainability, at the cost 368# of multiple if statements. 369 370# create completions 371complete -c zfs -f -n'__fish_zfs_using_command create' -s p -d'Create all needed non-existing parent datasets' 372if test $OS = Linux# Only Linux supports the comma-separated format; others need multiple -o calls 373complete -c zfs -x -n'__fish_zfs_using_command create' -s o -d'Dataset property' -a'(__fish_append , (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties))' 374end 375complete -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; __fish_zfs_complete_property_values (commandline -t))' 376# create completions for volumes; as -V is necessary to zfs to recognize a volume creation request, 377# we use it as a condition to propose volume creation completions. 378# If -V is typed after -s or -b, zfs should accept it, but fish won't propose -s or -b, but, as 379# these options are for volumes only, it seems reasonable to expect the user to ask for a volume, 380# with -V, before giving its characteristics with -s or -b 381complete -c zfs -x -n'__fish_zfs_using_command create' -s V -d'Volume size' 382complete -c zfs -f -n'__fish_zfs_using_command create; and __fish_contains_opt -s V' -s s -d'Create a sparse volume' 383complete -c zfs -x -n'__fish_zfs_using_command create; and __fish_contains_opt -s V' -s b -d Blocksize 384# new dataset completions, applicable for both regular datasets and volumes; must start with pool 385# and may optionally be a child of a pre-existing dataset. 386complete -c zfs -x -n'__fish_zfs_using_command create' -a'(printf "%s/\n" (__fish_print_zfs_filesystems))' 387 388# destroy completions; as the dataset is the last item, we can't know yet if it's a snapshot, a 389# bookmark or something else, so we can't separate snapshot-specific options from others. 390complete -c zfs -f -n'__fish_zfs_using_command destroy' -s r -d'Recursively destroy children' 391complete -c zfs -f -n'__fish_zfs_using_command destroy' -s R -d'Recursively destroy all dependents' 392complete -c zfs -f -n'__fish_zfs_using_command destroy' -s f -d'Force unmounting' 393complete -c zfs -f -n'__fish_zfs_using_command destroy' -s n -d'Dry run' 394complete -c zfs -f -n'__fish_zfs_using_command destroy' -s p -d'Print machine-parsable verbose information' 395complete -c zfs -f -n'__fish_zfs_using_command destroy' -s v -d'Verbose mode' 396complete -c zfs -f -n'__fish_zfs_using_command destroy' -s d -d'Defer snapshot deletion' 397complete -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)' 398 399# snapshot completions 400complete -c zfs -f -n'__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap' -s r -d'Recursively snapshot children' 401if test $OS = Linux# Only Linux supports the comma-separated format; others need multiple -o calls 402complete -c zfs -x -n'__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap' -s o -d'Snapshot property' -a'(__fish_append , (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties))' 403end 404complete -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; __fish_zfs_complete_property_values (commandline -t))' 405complete -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)' 406 407# rollback completions 408complete -c zfs -f -n'__fish_zfs_using_command rollback' -s r -d'Destroy later snapshot and bookmarks' 409complete -c zfs -f -n'__fish_zfs_using_command rollback' -s R -d'Recursively destroy later snapshot, bookmarks and clones' 410complete -c zfs -f -n'__fish_zfs_using_command rollback; and __fish_contains_opt -s R' -s f -d'Force unmounting of clones' 411complete -c zfs -x -n'__fish_zfs_using_command rollback' -d'Snapshot to roll back to' -a'(__fish_print_zfs_snapshots --force)' 412 413# clone completions 414complete -c zfs -f -n'__fish_zfs_using_command clone' -s p -d'Create all needed non-existing parent datasets' 415if test $OS = Linux# Only Linux supports the comma-separated format; others need multiple -o calls 416complete -c zfs -x -n'__fish_zfs_using_command clone' -s o -d'Clone property' -a'(__fish_append , (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties))' 417end 418complete -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; __fish_zfs_complete_property_values (commandline -t))' 419complete -c zfs -x -n'__fish_zfs_using_command clone' -d'Snapshot to clone' -a'(__fish_print_zfs_snapshots --force)' 420 421# promote completions 422complete -c zfs -x -n'__fish_zfs_using_command promote' -d'Clone to promote' -a'(__fish_print_zfs_filesystems)' 423 424# rename completions; as the dataset is the last item, we can't know yet if it's a snapshot or not, 425# we can't separate snapshot-specific option from others. 426complete -c zfs -f -n'__fish_zfs_using_command rename' -s p -d'Create all needed non-existing parent datasets' 427complete -c zfs -f -n'__fish_zfs_using_command rename' -s r -d'Recursively rename children snapshots' 428if __fish_is_openzfs 429complete -c zfs -f -n'__fish_zfs_using_command rename' -s f -d'Force unmounting if needed' 430end 431# These FreeBSD completions are in addition to any added via the OpenZFS check above 432if test $OS = FreeBSD 433complete -c zfs -f -n'__fish_zfs_using_command rename' -s u -d'Do not remount filesystems during rename' 434end 435complete -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)' 436 437# list completions 438complete -c zfs -f -n'__fish_zfs_using_command list' -s H -d'Print output in a machine-parsable format' 439complete -c zfs -f -n'__fish_zfs_using_command list' -s r -d'Operate recursively on datasets' 440complete -c zfs -x -n'__fish_zfs_using_command list; and __fish_contains_opt -s r' -s d -d'Maximum recursion depth' 441complete -c zfs -x -n'__fish_zfs_using_command list' -s o -d'Property to list' -a'(__fish_append , (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties; __fish_complete_zfs_ro_properties; echo -e "name\tDataset name"; echo -e "space\tSpace properties"))' 442complete -c zfs -f -n'__fish_zfs_using_command list' -s p -d'Print parsable (exact) values for numbers' 443complete -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\tDataset name")' 444complete -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\tDataset name")' 445complete -c zfs -x -n'__fish_zfs_using_command list' -s t -d'Dataset type' -a'(__fish_zfs_list_dataset_types)' 446complete -c zfs -x -n'__fish_zfs_using_command list' -d'Dataset whose properties to list' -a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)' 447 448# set completions (zfs set PROP VALUE POOL/DATASET) 449complete -c zfs -x -n'__fish_zfs_using_command set; and __fish_is_nth_token 2' -d'Property to set' -a'(__fish_complete_zfs_rw_properties)' 450complete -c zfs -x -n'__fish_zfs_using_command set; and __fish_is_nth_token 3' -d'Dataset whose property to set' -a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)' 451# set property value completions 452complete -c zfs -x -n'__fish_zfs_using_command set; and __fish_is_nth_token 2' -a'(__fish_zfs_complete_property_values (__fish_nth_token 2))' 453 454# get completions 455complete -c zfs -f -n'__fish_zfs_using_command get' -s r -d'Operate recursively on datasets' 456complete -c zfs -x -n'__fish_zfs_using_command get; and __fish_contains_opt -s r' -s d -d'Maximum recursion depth' 457complete -c zfs -f -n'__fish_zfs_using_command get' -s H -d'Print output in a machine-parsable format' 458complete -c zfs -x -n'__fish_zfs_using_command get' -s o -d'Fields to display' -a'(__fish_append , (__fish_zfs_list_get_fields))' 459complete -c zfs -x -n'__fish_zfs_using_command get' -s s -d'Property source to display' -a'(__fish_append , (__fish_zfs_list_source_types))' 460complete -c zfs -f -n'__fish_zfs_using_command get' -s p -d'Print parsable (exact) values for numbers' 461complete -c zfs -x -n'__fish_zfs_using_command get' -s t -d'Dataset type' -a'(__fish_append , (__fish_zfs_list_dataset_types))' 462complete -c zfs -x -n'__fish_zfs_using_command get' -d'Property to get' -a'(__fish_append , (__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties; __fish_complete_zfs_ro_properties; echo "all"))' 463complete -c zfs -x -n'__fish_zfs_using_command get' -d'Dataset whose property to get' -a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)' 464 465# inherit completions 466complete -c zfs -f -n'__fish_zfs_using_command inherit' -s r -d'Operate recursively on datasets' 467complete -c zfs -f -n'__fish_zfs_using_command inherit' -s S -d'Revert to the received value if available' 468complete -c zfs -x -n'__fish_zfs_using_command inherit' -d'Dataset whose properties are to be inherited' -a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)' 469 470# upgrade completions 471complete -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' 472complete -c zfs -f -n'__fish_zfs_using_command upgrade; and __fish_not_contain_opt -s v' -s a -d'Upgrade all eligible filesystems' 473complete -c zfs -f -n'__fish_zfs_using_command upgrade; and __fish_not_contain_opt -s v' -s r -d'Operate recursively on datasets' 474complete -c zfs -x -n'__fish_zfs_using_command upgrade; and __fish_not_contain_opt -s v' -s V -d'Upgrade to the specified version' 475complete -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)' 476 477# userspace/groupspace completions 478complete -c zfs -f -n'__fish_zfs_using_command userspace' -s n -d'Print UID instead of user name' 479complete -c zfs -f -n'__fish_zfs_using_command groupspace' -s n -d'Print GID instead of group name' 480complete -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' 481complete -c zfs -f -n'__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace' -s p -d'Print parsable (exact) values for numbers' 482complete -c zfs -x -n'__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace' -s o -d'Field to display' -a'(__fish_append , (__fish_zfs_list_space_fields))' 483complete -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 484complete -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 485complete -c zfs -x -n'__fish_zfs_using_command userspace' -s t -d'Identity types to display' -a'(__fish_append , (__fish_zfs_list_userspace_types))' 486complete -c zfs -x -n'__fish_zfs_using_command groupspace' -s t -d'Identity types to display' -a'(__fish_append , (__fish_zfs_list_groupspace_types))' 487complete -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' 488complete -c zfs -x -n'__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace' -d'Dataset whose space usage to get' -a'(__fish_print_zfs_filesystems; __fish_print_zfs_snapshots)' 489 490# mount completions 491if test $OS = Linux 492complete -c zfs -x -n'__fish_zfs_using_command mount' -s o -d'Temporary mount point property' -a'(__fish_append , (__fish_complete_zfs_mountpoint_properties))' 493end 494complete -c zfs -x -n'__fish_zfs_using_command mount' -s o -d'Temporary mount point property' -a'(__fish_complete_zfs_mountpoint_properties; __fish_zfs_complete_property_values (commandline -t))' 495complete -c zfs -f -n'__fish_zfs_using_command mount' -s v -d'Report progress' 496complete -c zfs -f -n'__fish_zfs_using_command mount' -s a -d'Mount all available ZFS filesystems' 497if contains --$OS Linux SunOS 498complete -c zfs -f -n'__fish_zfs_using_command mount' -s O -d'Overlay mount' 499end 500complete -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)' 501 502# unmount completions 503complete -c zfs -f -n'__fish_zfs_using_command unmount; or __fish_zfs_using_command umount' -s f -d'Force unmounting if needed' 504complete -c zfs -f -n'__fish_zfs_using_command unmount; or __fish_zfs_using_command umount' -s a -d'Unmount all available ZFS filesystems' 505complete -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)' 506 507# share completions 508complete -c zfs -f -n'__fish_zfs_using_command share' -s a -d'Share all eligible ZFS filesystems' 509complete -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)' 510 511# unshare completions 512complete -c zfs -f -n'__fish_zfs_using_command unshare' -s a -d'Unshare all shared ZFS filesystems' 513complete -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)' 514 515# bookmark completions 516if __fish_is_zfs_feature_enabled 'feature@bookmarks' 517complete -c zfs -x -n'__fish_zfs_using_command bookmark' -d'Snapshot to bookmark' -a'(__fish_print_zfs_snapshots)' 518end 519 520# send completions 521complete -c zfs -x -n'__fish_zfs_using_command send' -s i -d'Generate incremental stream from snapshot' -a'(__fish_print_zfs_snapshots --force; __fish_print_zfs_bookmarks)' 522complete -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 --force)' 523if test $OS = SunOS 524complete -c zfs -f -n'__fish_zfs_using_command send' -s R -l replicate -d'Include children in replication stream' 525complete -c zfs -f -n'__fish_zfs_using_command send' -s D -l dedup -d'Generate a deduplicated stream' 526complete -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' 527complete -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' 528complete -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' 529complete -c zfs -f -n'__fish_zfs_using_command send' -s c -l compressed -d'Generate compressed stream' 530complete -c zfs -f -n'__fish_zfs_using_command send' -s n -l dryrun -d'Dry run' 531complete -c zfs -f -n'__fish_zfs_using_command send; and __fish_not_contain_opt -s R' -s p -l props -d'Include dataset properties' 532complete -c zfs -f -n'__fish_zfs_using_command send' -s v -l verbose -d'Print verbose information about the stream' 533else 534complete -c zfs -f -n'__fish_zfs_using_command send' -s R -d'Include children in replication stream' 535complete -c zfs -f -n'__fish_zfs_using_command send' -s D -d'Generate a deduplicated stream' 536complete -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' 537complete -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' 538complete -c zfs -f -n'__fish_zfs_using_command send' -s P -d'Print verbose information about the stream in a machine-parsable format' 539complete -c zfs -f -n'__fish_zfs_using_command send' -s n -d'Dry run' 540complete -c zfs -f -n'__fish_zfs_using_command send; and __fish_not_contain_opt -s R' -s p -d'Include dataset properties' 541complete -c zfs -f -n'__fish_zfs_using_command send' -s v -d'Print verbose information about the stream' 542end 543# Only snapshots (and bookmarks?) may be sent 544complete -c zfs -x -n'__fish_zfs_using_command send' -d'Dataset to send' -a'(__fish_print_zfs_snapshots --force)' 545 546# receive completions 547complete -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' 548complete -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' 549complete -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' 550complete -c zfs -f -n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv' -s u -d'Unmount the target filesystem' 551complete -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' 552complete -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' 553if test $OS = SunOS 554complete -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 555end 556if __fish_is_zfs_feature_enabled "feature@extensible_dataset" 557complete -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' 558end 559complete -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;)' 560 561# allow completions 562complete -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' 563complete -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' 564complete -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_append , (__fish_complete_users))' 565complete -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_append , (__fish_complete_groups))' 566if contains --$OS SunOS FreeBSD 567complete -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' 568end 569complete -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' 570complete -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_append , (__fish_zfs_list_permissions))' 571complete -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' 572complete -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)' 573 574# unallow completions 575complete -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' 576complete -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' 577complete -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_append , (__fish_complete_users))' 578complete -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_append , (__fish_complete_groups))' 579complete -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' 580complete -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_append , (__fish_zfs_list_permissions))' 581complete -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' 582if test $OS = SunOS 583complete -c zfs -f -n'__fish_zfs_using_command unallow' -s r -d'Remove permissions recursively' 584complete -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' 585else if test $OS = FreeBSD 586complete -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' 587end 588complete -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)' 589 590# hold completions 591complete -c zfs -f -n'__fish_zfs_using_command hold' -s r -d'Apply hold recursively' 592complete -c zfs -x -n'__fish_zfs_using_command hold' -d'Snapshot on which hold is to be applied' -a'(__fish_print_zfs_snapshots)' 593 594# holds completions 595complete -c zfs -f -n'__fish_zfs_using_command holds' -s r -d'List holds recursively' 596complete -c zfs -x -n'__fish_zfs_using_command holds' -d'Snapshot whose holds are to be listed' -a'(__fish_print_zfs_snapshots)' 597 598# release completions 599complete -c zfs -f -n'__fish_zfs_using_command release' -s r -d'Release hold recursively' 600complete -c zfs -x -n'__fish_zfs_using_command release' -d'Snapshot from which hold is to be removed' -a'(__fish_print_zfs_snapshots)' 601 602# diff completions 603complete -c zfs -f -n'__fish_zfs_using_command diff' -s F -d'Display file type (à la ls -F)' 604complete -c zfs -f -n'__fish_zfs_using_command diff' -s H -d'Print output in a machine-parsable format' 605complete -c zfs -f -n'__fish_zfs_using_command diff' -s t -d'Display inode change time' 606complete -c zfs -x -n'__fish_zfs_using_command diff' -d'Source snapshot for the diff' -a'(__fish_print_zfs_snapshots)' 607 608# program completions 609if test $OS = SunOS# This is currently only supported under Illumos, but that will probably change 610complete -c zfs -x -n'__fish_zfs_using_command program' -s t -d'Execution timeout' 611complete -c zfs -x -n'__fish_zfs_using_command program' -s t -d'Execution memory limit' 612complete -c zfs -x -n'__fish_zfs_using_command program' -d'Pool program will be executed on' -a'(__fish_complete_zfs_pools)' 613end 614 615# encryption-related completions 616complete -c zfs -f -n'__fish_zfs_using_command load-key' -s n -d'Dry run; checks but doesn\'t load' 617complete -c zfs -f -n'__fish_zfs_using_command load-key' -s r -d'Recursively load key for child datasets' 618complete -c zfs -f -n'__fish_zfs_using_command load-key' -s a -d'Load keys for all imported pools' 619complete -c zfs -n'__fish_zfs_using_command load-key' -s L -d'Key location' -r 620# todo: maybe query properties to list only encrypted datasets (that haven't had their keys loaded) 621complete -c zfs -n'__fish_zfs_using_command load-key' -d'Dataset to load key for' -xa'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)' 622 623complete -c zfs -f -n'__fish_zfs_using_command unload-key' -s r -d'Recursively unload key for child datasets' 624complete -c zfs -f -n'__fish_zfs_using_command unload-key' -s a -d'Unload keys for all imported pools' 625# todo: maybe query properties to list only encrypted datasets (that have had their keys loaded) 626complete -c zfs -n'__fish_zfs_using_command unload-key' -d'Dataset to unload key for' -xa'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)' 627 628complete -c zfs -f -n'__fish_zfs_using_command change-key' -s l -d'Ensure key is loaded before changing key' 629complete -c zfs -f -n'__fish_zfs_using_command change-key' -s i -d'Inherit key from its parent' 630complete -c zfs -f -n'__fish_zfs_using_command change-key' -s o -xa"keylocation=file:///" -d"Absolute path to key" 631complete -c zfs -f -n'__fish_zfs_using_command change-key' -s o -xa"keylocation=prompt" -d"Obtain key from stdin" 632complete -c zfs -f -n'__fish_zfs_using_command change-key' -s o -xa"keyformat=hex keyformat=raw keyformat=passphrase" 633complete -c zfs -f -n'__fish_zfs_using_command change-key' -s o -xa"keyformat=hex keyformat=raw keyformat=passphrase" 634complete -c zfs -f -n'__fish_zfs_using_command change-key' -s o -xa"pbkdf2iters=" -d"Specify PBKDF2 iteration count" 635# todo: maybe query properties to list only encrypted datasets 636complete -c zfs -f -n'__fish_zfs_using_command change-key' -d"Dataset to change wrapper key for" -xa"(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)"