fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

ccoVeilleFix typos in completions scripts0df6fa791

master
43.1 KiB636 linesraw
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)
20    case Linux
21        set OS Linux
22    case Darwin
23        set OS macOS
24    case FreeBSD
25        set OS FreeBSD
26        set freebsd_version (uname -U)
27    case SunOS
28        set OS SunOS
29        # Others?
30    case "*"
31        set 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
37    function __fish_is_openzfs --inherit-variable freebsd_version --inherit-variable OS
38        test $OS = Linux || test $OS = FreeBSD -a $freebsd_version -gt 1300000
39    end
40end
41
42# Does the current invocation need a command?
43function __fish_zfs_needs_command
44    set -l bookmark ""
45    if __fish_is_zfs_feature_enabled "feature@bookmarks"
46        set bookmark bookmark
47    end
48
49    not __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
53    set -l cmd (commandline -xpc)
54    if test (count $cmd) -eq 1 # The token can only be 'zfs', so skip
55        return 2
56    end
57    if test $cmd[2] = $argv
58        return 0
59    else
60        return 1
61    end
62end
63
64function __fish_zfs_list_dataset_types
65    echo -e "filesystem\tZFS filesystem"
66    echo -e "snapshot\tZFS filesystem snapshot"
67    echo -e "volume\tZFS block storage device"
68    echo -e "bookmark\tZFS snapshot bookmark"
69    echo -e "all\tAny ZFS dataset"
70end
71
72function __fish_zfs_list_source_types
73    echo -e "local\tDataset-specific value"
74    echo -e "default\tDefault ZFS value"
75    echo -e "inherited\tValue inherited from parent dataset"
76    echo -e "received\tValue received by 'zfs receive'"
77    echo -e "temporary\tValue valid for the current mount"
78    echo -e "none\tRead-only value"
79end
80
81function __fish_zfs_list_get_fields
82    echo -e "name\tDataset full name"
83    echo -e "property\tProperty"
84    echo -e "value\tProperty value"
85    echo -e "source\tProperty value origin"
86end
87
88function __fish_zfs_list_space_fields
89    echo -e "type\tIdentity type"
90    echo -e "name\tIdentity name"
91    echo -e "used\tSpace usage"
92    echo -e "quota\tSpace quota"
93end
94
95function __fish_zfs_list_userspace_types
96    echo -e "posixuser\tPOSIX user"
97    echo -e "smbuser\tSamba user"
98    echo -e "all\tBoth types"
99end
100
101function __fish_zfs_list_groupspace_types
102    echo -e "posixgroup\tPOSIX group"
103    echo -e "smbgroup\tSamba group"
104    echo -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
111    set all_options "
112    aclinherit=discard|noallow|restricted|passthrough|passthrough-x
113    aclmode=discard|groupmask|passthrough|restricted
114    acltype=off|nfsv4|posix
115    atime=on|off
116    canmount=on|off|noauto
117    checksum=on|off|fletcher2|fletcher4|sha256|noparity|sha512|skein|edonr
118    compression=on|off|gzip|gzip-N|lz4|lzjb|zle|zstd|zstd-N|zstd-fast|zstd-fast-N
119    context=none|SELinux_User:SElinux_Role:Selinux_Type:Sensitivity_Level
120    fscontext=none|SELinux_User:SElinux_Role:Selinux_Type:Sensitivity_Level
121    defcontext=none|SELinux_User:SElinux_Role:Selinux_Type:Sensitivity_Level
122    rootcontext=none|SELinux_User:SElinux_Role:Selinux_Type:Sensitivity_Level
123    copies=1|2|3
124    devices=on|off
125    dedup=off|on|verify|sha256[,verify]|sha512[,verify]|skein[,verify]|edonr,verify
126    dnodesize=legacy|auto|1k|2k|4k|8k|16k
127    encryption=off|on|aes-128-ccm|aes-192-ccm|aes-256-ccm|aes-128-gcm|aes-192-gcm|aes-256-gcm
128    keyformat=raw|hex|passphrase
129    keylocation=prompt|file://</absolute/file/path>
130    pbkdf2iters=iterations
131    exec=on|off
132    filesystem_limit=count|none
133    special_small_blocks=size
134    mountpoint=path|none|legacy
135    nbmand=on|off
136    overlay=on|off
137    primarycache=all|none|metadata
138    quota=size|none
139    snapshot_limit=count|none
140    recordsize=size
141    readonly=on|off
142    redundant_metadata=all|most
143    refquota=size|none
144    refreservation=size|none|auto
145    relatime=on|off
146    reservation=size|none
147    secondarycache=all|none|metadata
148    setuid=on|off
149    sharesmb=on|off|opts
150    sharenfs=on|off|opts
151    logbias=latency|throughput
152    snapdev=hidden|visible
153    snapdir=hidden|visible
154    sync=standard|always|disabled
155    version=N|current
156    volsize=size
157    volmode=default | full | geom | dev | none
158    vscan=on|off
159    xattr=on|off|sa
160    jailed=off | on
161    casesensitivity=sensitive|insensitive|mixed
162    normalization=none|formC|formD|formKC|formKD
163    utf8only=on|off
164    keyformat=raw|passphrase|hex
165    keylocation=stdin|file:///
166    encryption=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
169    set 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)
172    set name (string match -r '^[^=]+' -- $name)
173    # Extract the values "value1|value2" from the long list of "key=value1|value2"
174    set 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
177    set options (string replace -a '|' \n -- $options | string trim)
178    # echo o2: (string escape -- $options)
179    # Remove open-ended options (size, count, path)
180    set 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)
183    set options (string replace -r "(.*)\[,(.*?)\]" '$1\n$1,$2' -- $options)
184    # echo o4: (string escape -- $options)
185
186    if set -q options[1]
187        printf "$name=%s\n" $options
188    end
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
194    function __fish_zfs_property_options
195        set -l property (string escape --style=regex -- $argv[1])
196        set -l values (command man zfs | col -b | string replace -rf -- '^\s*'$property'=(.*\|.*)' '$1' | string split ' | ')
197        printf '%s\n' $property=$values
198    end
199else
200    function __fish_zfs_property_options
201    end
202end
203
204function __fish_zfs_list_permissions -V OS
205    echo -e "allow\tAlso needs the permission to be allowed"
206    echo -e "clone\tAlso needs the 'create' and 'mount' permissions in the origin filesystem"
207    echo -e "create\tAlso needs the 'mount' permission"
208    echo -e "destroy\tAlso needs the 'mount' permission"
209    echo -e mount
210    echo -e "promote\tAlso needs the 'promote' and 'mount' permissions in the origin filesystem"
211    echo -e "receive\tAlso needs the 'create' and 'mount' permissions"
212    echo -e "rename\tAlso needs the 'create' and 'mount' permissions in the new parent"
213    echo -e "rollback\tAlso needs the 'mount' permission"
214    echo -e send
215    echo -e "share\tFor SMB and NFS shares"
216    echo -e "snapshot\tAlso needs the 'mount' permission"
217    echo -e groupquota
218    echo -e groupused
219    echo -e "userprop\tAllows changing any user property"
220    echo -e userquota
221    echo -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
224    echo -e "volblocksize\tVolume block size"
225    # R/W properties
226    echo -e "aclinherit\tInheritance of ACL entries (discard, noallow, restricted, passthrough, passthrough-x)"
227    echo -e "atime\tUpdate access time on read (on, off)"
228    echo -e "canmount\tIs the dataset mountable (on, off, noauto)"
229    set -l additional_cksum_algs ''
230    set -l additional_dedup_algs ''
231    if contains -- $OS FreeBSD SunOS
232        set additional_cksum_algs ", noparity"
233    end
234    if __fish_is_zfs_feature_enabled "feature@sha512"
235        set additional_cksum_algs "$additional_cksum_algs, sha512"
236        set additional_dedup_algs ", sha512[,verify]"
237    end
238    if __fish_is_zfs_feature_enabled "feature@skein"
239        set additional_cksum_algs "$additional_cksum_algs, skein"
240        set additional_dedup_algs "$additional_dedup_algs, skein[,verify]"
241    end
242    if __fish_is_zfs_feature_enabled "feature@edonr"
243        set additional_cksum_algs "$additional_cksum_algs, edonr"
244        set additional_dedup_algs "$additional_dedup_algs, edonr[,verify]"
245    end
246    echo -e "checksum\tData checksum (on, off, fletcher2, fletcher4, sha256$additional_cksum_algs)"
247    set -e additional_cksum_algs
248    set -l additional_compress_algs ''
249    if __fish_is_zfs_feature_enabled "feature@lz4_compress"
250        set additional_compress_algs ", lz4"
251    end
252    echo -e "compression\tCompression algorithm (on, off, lzjb$additional_compress_algs, gzip, gzip-[1-9], zle)"
253    set -e additional_compress_algs
254    echo -e "copies\tNumber of copies of data (1, 2, 3)"
255    echo -e "dedup\tDeduplication (on, off, verify, sha256[,verify]$additional_dedup_algs)"
256    set -e additional_dedup_algs
257    echo -e "devices\tAre contained device nodes openable (on, off)"
258    echo -e "exec\tCan contained executables be executed (on, off)"
259    echo -e "filesystem_limit\tMax number of filesystems and volumes (COUNT, none)"
260    echo -e "mountpoint\tMountpoint (PATH, none, legacy)"
261    echo -e "primarycache\tWhich data to cache in ARC (all, none, metadata)"
262    echo -e "quota\tMax size of dataset and children (SIZE, none)"
263    echo -e "snapshot_limit\tMax number of snapshots (COUNT, none)"
264    echo -e "readonly\tRead-only (on, off)"
265    echo -e "recordsize\tSuggest block size (SIZE)"
266    echo -e "redundant_metadata\tHow redundant are the metadata (all, most)"
267    echo -e "refquota\tMax space used by dataset itself (SIZE, none)"
268    echo -e "refreservation\tMin space guaranteed to dataset itself (SIZE, none)"
269    echo -e "reservation\tMin space guaranteed to dataset (SIZE, none)"
270    echo -e "secondarycache\tWhich data to cache in L2ARC (all, none, metadata)"
271    echo -e "setuid\tRespect set-UID bit (on, off)"
272    echo -e "sharenfs\tShare in NFS (on, off, OPTS)"
273    echo -e "logbias\tHint for handling of synchronous requests (latency, throughput)"
274    echo -e "snapdir\tHide .zfs directory (hidden, visible)"
275    echo -e "sync\tHandle of synchronous requests (standard, always, disabled)"
276    echo -e "volsize\tVolume logical size (SIZE)"
277    if test $OS = SunOS
278        echo -e "zoned\tManaged from a non-global zone (on, off)"
279        echo -e "mlslabel\tCan the dataset be mounted in a zone with Trusted Extensions enabled (LABEL, none)"
280        echo -e "nbmand\tMount with Non Blocking mandatory locks (on, off)"
281        echo -e "sharesmb\tShare in Samba (on, off)"
282        echo -e "shareiscsi\tShare as an iSCSI target (on, off)"
283        echo -e "version\tOn-disk version of filesystem (1, 2, current)"
284        echo -e "vscan\tScan regular files for viruses on opening and closing (on, off)"
285        echo -e "xattr\tExtended attributes (on, off, sa)"
286    else if test $OS = Linux
287        echo -e "acltype\tUse no ACL or POSIX ACL (noacl, posixacl)"
288        echo -e "nbmand\tMount with Non Blocking mandatory locks (on, off)"
289        echo -e "relatime\tSometimes update access time on read (on, off)"
290        echo -e "shareiscsi\tShare as an iSCSI target (on, off)"
291        echo -e "sharesmb\tShare in Samba (on, off)"
292        echo -e "snapdev\tHide volume snapshots (hidden, visible)"
293        echo -e "version\tOn-disk version of filesystem (1, 2, current)"
294        echo -e "vscan\tScan regular files for viruses on opening and closing (on, off)"
295        echo -e "xattr\tExtended attributes (on, off, sa)"
296    else if test $OS = FreeBSD
297        echo -e "aclmode\tHow is ACL modified by chmod (discard, groupmask, passthrough, restricted)"
298        echo -e "volmode\tHow to expose volumes to OS (default, geom, dev, none)"
299    end
300    # Write-once properties
301    echo -e "normalization\tUnicode normalization (none, formC, formD, formKC, formKD)"
302    echo -e "utf8only\tReject non-UTF-8-compliant filenames (on, off)"
303    if test $OS = Linux
304        echo -e "casesensitivity\tCase sensitivity (sensitive, insensitive)"
305    else # FreeBSD, SunOS and virtually all others
306        echo -e "casesensitivity\tCase sensitivity (sensitive, insensitive, mixed)"
307    end
308    # Permissions set; if none are found, or if permission sets are not supported, no output is expected, even an error
309    for i in (zpool list -o name -H)
310        zfs allow $i
311    end | string match -r '@[[:alnum:]]*' | sort -u
312end
313
314function __fish_print_zfs_bookmarks -d "Lists ZFS bookmarks, if the feature is enabled"
315    if __fish_is_zfs_feature_enabled 'feature@bookmarks'
316        zfs list -t bookmark -o name -H
317    end
318end
319
320function __fish_print_zfs_filesystems -d "Lists ZFS filesystems"
321    zfs list -t filesystem -o name -H
322end
323
324function __fish_print_zfs_volumes -d "Lists ZFS volumes"
325    zfs 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'
348    complete -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
359    complete -c zfs -f -n __fish_zfs_needs_command -a program -d 'Execute a ZFS Channel Program'
360end
361if __fish_is_openzfs
362    complete -c zfs -f -n __fish_zfs_needs_command -a load-key -d "Load encryption key for dataset"
363    complete -c zfs -f -n __fish_zfs_needs_command -a unload-key -d "Unload encryption key for dataset"
364    complete -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
373    complete -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
402    complete -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
416    complete -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
429    complete -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
433    complete -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
492    complete -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
498    complete -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'
517    complete -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
524    complete -c zfs -f -n '__fish_zfs_using_command send' -s R -l replicate -d 'Include children in replication stream'
525    complete -c zfs -f -n '__fish_zfs_using_command send' -s D -l dedup -d 'Generate a deduplicated stream'
526    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'
527    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'
528    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'
529    complete -c zfs -f -n '__fish_zfs_using_command send' -s c -l compressed -d 'Generate compressed stream'
530    complete -c zfs -f -n '__fish_zfs_using_command send' -s n -l dryrun -d 'Dry run'
531    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'
532    complete -c zfs -f -n '__fish_zfs_using_command send' -s v -l verbose -d 'Print verbose information about the stream'
533else
534    complete -c zfs -f -n '__fish_zfs_using_command send' -s R -d 'Include children in replication stream'
535    complete -c zfs -f -n '__fish_zfs_using_command send' -s D -d 'Generate a deduplicated stream'
536    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'
537    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'
538    complete -c zfs -f -n '__fish_zfs_using_command send' -s P -d 'Print verbose information about the stream in a machine-parsable format'
539    complete -c zfs -f -n '__fish_zfs_using_command send' -s n -d 'Dry run'
540    complete -c zfs -f -n '__fish_zfs_using_command send; and __fish_not_contain_opt -s R' -s p -d 'Include dataset properties'
541    complete -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
554    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
555end
556if __fish_is_zfs_feature_enabled "feature@extensible_dataset"
557    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'
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
567    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'
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
583    complete -c zfs -f -n '__fish_zfs_using_command unallow' -s r -d 'Remove permissions recursively'
584    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'
585else if test $OS = FreeBSD
586    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'
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
610    complete -c zfs -x -n '__fish_zfs_using_command program' -s t -d 'Execution timeout'
611    complete -c zfs -x -n '__fish_zfs_using_command program' -s t -d 'Execution memory limit'
612    complete -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)"