fork/fish-shell

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

Johannes AltmanningerMerge key decoding fixes8585def79

master
28.4 KiB457 linesraw
1# Fish completions for the ZFS `zpool` command
2#
3# Possible improvements:
4# - Whenever possible, propose designation of vdevs using their GUID.
5# - For eligible commands, with arguments of different types, only propose second type completions
6#   after the first have been selected; for instance, only propose pool members for offline command.
7# - This has been written mainly from manpages, which are known to be out-of-sync with the real
8#   feature set; some discrepancies have been addressed, but it is highly likely that others still
9#   lie.
10
11set -l OS ""
12set -l freebsd_version ""
13switch (uname)
14    case Linux
15        set OS Linux
16    case Darwin
17        set OS macOS
18    case FreeBSD
19        set OS FreeBSD
20        set freebsd_version (uname -U)
21    case SunOS
22        set OS SunOS
23        # Others?
24    case "*"
25        set OS unknown
26end
27
28# Certain functionality is exclusive to platforms using OpenZFS. This used to be just Linux, but it
29# now includes FreeBSD 13 and above.
30if not type -q __fish_is_openzfs
31    function __fish_is_openzfs --inherit-variable freebsd_version --inherit-variable OS
32        test $OS = Linux || test $OS = FreeBSD -a $freebsd_version -gt 1300000
33    end
34end
35
36# Does the current invocation need a command?
37function __fish_zpool_needs_command
38    not __fish_seen_subcommand_from \? add attach clear create destroy detach events get history import iostat labelclear list offline online reguid reopen remove replace scrub set split status upgrade
39end
40
41function __fish_zpool_using_command # zpool command whose completions are looked for
42    set -l cmd (commandline -xpc)
43    if test (count $cmd) -eq 1 # The token can only be 'zpool', so skip
44        return 2
45    end
46    if test $cmd[2] = $argv
47        return 0
48    else
49        return 1
50    end
51end
52
53function __fish_zpool_list_used_vdevs -a pool
54    # See discussion and variants discussed at
55    # https://github.com/fish-shell/fish-shell/pull/5743#pullrequestreview-217432149
56    zpool list -Hv $pool | string replace -rf "^\t([^\t]+).*" '$1' | string match -rv '^(spare|log|cache|mirror|raidz.?)'
57end
58
59function __fish_zpool_list_available_vdevs -V OS
60    if test $OS = Linux
61        find /dev -type b | string replace /dev/ ''
62    else if test $OS = FreeBSD
63        # all adaXX/daXX/etc block device identifiers, no leading /dev/, cds and floppies excluded (e.g. emulated)
64        printf "%s\n" /dev/(sysctl -an kern.disks | string split ' ')* | string replace -rf "/dev/((?!cd|fd).*)" '$1'
65        # serial-based disk paths (e.g. /dev/diskid/DISK-XXXX printed as diskid/DISK-XXXX)
66        if path is -d /dev/diskid
67            # Not using wildcards to prevent an error if empty
68            printf "diskid/%s\n" (ls /dev/diskid)
69        end
70    else if test $OS = SunOS
71        find /dev/dsk -type b | string replace /dev/ ''
72    end
73end
74
75function __fish_zpool_complete_vdevs
76    # As this function is to be called for completions only when necessary, we don't need to verify
77    # that it is relevant for the specified command; this is to be decided by calling, or not, the
78    # current function for command completions.
79    # We can display the physical devices, as they are relevant whereas we are in a vdev definition
80    # or not. Many operations need this list of vdevs winnowed down to some precondition (mostly
81    # "vdevs associated with pool" or "vdevs not associated with pool") but it's not really feasible
82    # to do that here as the situations are highly subcommand-dependent and this function is
83    # structured to operate backwards only analyzing the subcommand at the very end. Long story
84    # short, that vdev filtering will need to happen at the call site, at least currently.
85    __fish_zpool_list_available_vdevs
86
87    # First, reverse token list to analyze it from the end
88    set -l tokens 0
89    for i in (commandline -cx)[-1..1]
90        switch $i
91            case spare log cache # At least 1 item expected
92                if test $tokens -ge 1
93                    __fish_zpool_list_vdev_types
94                end
95                return
96            case mirror raidz raidz1 # At least 2 items expected
97                if test $tokens -ge 2
98                    __fish_zpool_list_vdev_types
99                end
100                return
101            case raidz2 # At least 3 items expected
102                if test $tokens -ge 3
103                    __fish_zpool_list_vdev_types
104                end
105                return
106            case raidz3 # At least 4 items expected
107                if test $tokens -ge 4
108                    __fish_zpool_list_vdev_types
109                end
110                return
111                # Here, we accept any possible zpool command; this way, the developer will not have
112                # to augment or reduce the list when adding the current function to or removing it
113                # from the completions for the said command.
114            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
115                __fish_zpool_list_vdev_types
116                return
117            case "" # Au cas où
118                echo "" >/dev/null
119            case "-*" "*=*" "*,*"
120                # The token is an option or an option argument; as no option uses a vdev as its
121                # argument, we can abandon commandline parsing.
122                __fish_zpool_list_vdev_types
123                return
124        end
125        set tokens (math $tokens+1)
126    end
127end
128
129# List all devices not associated with a pool, unless $except_pool is provided in which case
130# list all devices, including those associated with any pool other than $except_pool.
131function __fish_zpool_list_free_vdevs -a except_pool
132    set exclude_regex (
133        __fish_zpool_list_used_vdevs $except_pool \
134            | string escape --style=regex \
135            | string replace -r "(.*)" '^$1\$' \
136            | string join "|"
137    )
138    __fish_zpool_list_available_vdevs |
139        string match -vr $exclude_regex
140end
141
142function __fish_zpool_list_get_fields
143    echo -e "name\tPool full name"
144    echo -e "property\tProperty"
145    echo -e "value\tProperty value"
146    echo -e "source\tProperty value origin"
147end
148
149function __fish_zpool_list_vdev_types
150    echo -e "mirror\tMirror of at least two devices"
151    echo -e "raidz\tZFS RAID-5 variant, single parity"
152    echo -e "raidz1\tZFS RAID-5 variant, single parity"
153    echo -e "raidz2\tZFS RAID-5 variant, double parity"
154    echo -e "raidz3\tZFS RAID-5 variant, triple parity"
155    echo -e "spare\tPseudo vdev for pool hot spares"
156    echo -e "log\tSLOG device"
157    echo -e "cache\tL2ARC device"
158end
159
160function __fish_zpool_list_ro_properties -V OS
161    echo -e "alloc\tPhysically allocated space"
162    if contains -- $OS SunOS Linux
163        echo -e "available\tAvailable space"
164        echo -e "avail\tAvailable space"
165    end
166    if test $OS = SunOS
167        echo -e "bootsize\tSystem boot partition size"
168    end
169    echo -e "capacity\tUsage percentage of pool"
170    echo -e "dedupratio\tDeduplication ratio"
171    echo -e "expandsize\tAmount of uninitialized space within the pool"
172    echo -e "fragmentation\tFragmentation percentage of pool"
173    echo -e "free\tFree pool space"
174    echo -e "freeing\tRemaining pool space to be freed"
175    echo -e "guid\tPool GUID"
176    echo -e "health\tCurrent pool health"
177    echo -e "size\tTotal pool space"
178    echo -e "used\tUsed pool space"
179    # Unsupported features
180    zpool list -o all | head -n1 | string replace -ra ' +' '\n' | string lower | string match -r unsupported
181end
182
183function __fish_zpool_list_device_properties
184    echo -e "ashift\tPool sector size exponent (COUNT)"
185end
186
187function __fish_zpool_list_writeonce_properties
188    echo -e "altroot\tAlternate root directory (PATH)"
189end
190
191function __fish_zpool_list_importtime_properties
192    echo -e "altroot\tAlternate root directory (PATH)"
193    echo -e "readonly\tImport pool in read-only mode (on, off)"
194    echo -e "rdonly\tImport pool in read-only mode (on, off)"
195end
196
197function __fish_zpool_list_rw_properties
198    echo -e "autoexpand\tAutomatic pool expansion on LUN growing (on, off)"
199    echo -e "expand\tAutomatic pool expansion on LUN growing (on, off)"
200    echo -e "autoreplace\tAutomatic use of replacement device (on, off)"
201    echo -e "replace\tAutomatic use of replacement device (on, off)"
202    echo -e "bootfs\tDefault bootable dataset (POOL/DATASET)"
203    echo -e "cachefile\tPool configuration cache (PATH, none, '')"
204    echo -e "comment\tComment about the pool (COMMENT)"
205    echo -e "dedupditto\tThreshold for writing a ditto copy of deduplicated blocks (COUNT)"
206    echo -e "delegation\tAllow rights delegation on the pool (on, off)"
207    echo -e "failmode\tBehavior in case of catastrophic pool failure (wait, continue, panic)"
208    echo -e "listsnaps\tDisplay snapshots even if 'zfs list' does not use '-t' (on, off)"
209    echo -e "version\tOn-disk version of pool (VERSION)"
210    # Feature properties
211    zpool list -o all | string replace -ra ' +' '\n' | string lower | string replace -rf '^feature@(.*)' '$1'
212end
213
214complete -c zpool -f -n __fish_zpool_needs_command -s '?' -d 'Display a help message'
215complete -c zpool -f -n __fish_zpool_needs_command -a add -d 'Add new virtual devices to pool'
216complete -c zpool -f -n __fish_zpool_needs_command -a attach -d 'Attach virtual device to a pool device'
217complete -c zpool -f -n __fish_zpool_needs_command -a clear -d 'Clear devices errors in pool'
218complete -c zpool -f -n __fish_zpool_needs_command -a create -d 'Create a new storage pool'
219complete -c zpool -f -n __fish_zpool_needs_command -a destroy -d 'Destroy a storage pool'
220complete -c zpool -f -n __fish_zpool_needs_command -a detach -d 'Detach virtual device from a mirroring pool'
221if __fish_is_openzfs
222    complete -c zpool -f -n __fish_zpool_needs_command -a events -d 'Display pool event log'
223end
224complete -c zpool -f -n __fish_zpool_needs_command -a export -d 'Export a pool'
225complete -c zpool -f -n __fish_zpool_needs_command -a get -d 'Get one or several pool properties'
226complete -c zpool -f -n __fish_zpool_needs_command -a history -d 'Display pool command history'
227complete -c zpool -f -n __fish_zpool_needs_command -a import -d 'List importable pools, or import some'
228complete -c zpool -f -n __fish_zpool_needs_command -a iostat -d 'Display pool I/O stats'
229complete -c zpool -f -n __fish_zpool_needs_command -a labelclear -d 'Remove ZFS label information from the specified device'
230complete -c zpool -f -n __fish_zpool_needs_command -a list -d 'List pools with health status and space usage'
231complete -c zpool -f -n __fish_zpool_needs_command -a offline -d 'Take the specified devices offline'
232complete -c zpool -f -n __fish_zpool_needs_command -a online -d 'Bring the specified devices back online'
233complete -c zpool -f -n __fish_zpool_needs_command -a reguid -d 'Reset pool GUID'
234complete -c zpool -f -n __fish_zpool_needs_command -a remove -d 'Remove virtual devices from pool'
235complete -c zpool -f -n __fish_zpool_needs_command -a reopen -d 'Reopen pool devices'
236complete -c zpool -f -n __fish_zpool_needs_command -a replace -d 'Replace a pool virtual device'
237complete -c zpool -f -n __fish_zpool_needs_command -a scrub -d 'Start or stop scrubbing'
238complete -c zpool -f -n __fish_zpool_needs_command -a set -d 'Set a pool property'
239complete -c zpool -f -n __fish_zpool_needs_command -a split -d 'Create a pool by splitting an existing mirror one'
240complete -c zpool -f -n __fish_zpool_needs_command -a status -d 'Display detailed pool health status'
241complete -c zpool -f -n __fish_zpool_needs_command -a upgrade -d 'List upgradeable pools, or upgrade one'
242
243# add completions
244complete -c zpool -f -n '__fish_zpool_using_command add' -s f -d 'Force use of virtual device'
245complete -c zpool -f -n '__fish_zpool_using_command add' -s n -d 'Dry run: only display resulting configuration'
246if __fish_is_openzfs
247    complete -c zpool -f -n '__fish_zpool_using_command add' -s g -d 'Display virtual device GUID instead of device name'
248    complete -c zpool -f -n '__fish_zpool_using_command add' -s L -d 'Resolve device path symbolic links'
249    complete -c zpool -f -n '__fish_zpool_using_command add' -s P -d 'Display device full path'
250    complete -c zpool -x -n '__fish_zpool_using_command add' -s o -d 'Pool property' -a '(__fish_zpool_list_device_properties)'
251end
252complete -c zpool -x -n '__fish_zpool_using_command add; and __fish_is_nth_token 2' -d 'Pool to add virtual device(s) to' -a '(__fish_complete_zfs_pools)'
253# complete -c zpool -x -n '__fish_zpool_using_command add; and not __fish_prev_arg_in add' -d 'Virtual device to add' -a '(__fish_zpool_complete_vdevs)'
254# Exclude devices already part of this pool, and devices already in any other pool unless
255# `zpool add -f` was used.
256complete -c zpool -x -n '__fish_zpool_using_command add; and not __fish_prev_arg_in add' -k -d 'Virtual device to add' -a '(__fish_zpool_list_free_vdevs (__fish_seen_argument -s f && __fish_nth_token 2))'
257
258# attach completions
259complete -c zpool -f -n '__fish_zpool_using_command attach' -s f -d 'Force use of virtual device'
260if __fish_is_openzfs
261    complete -c zpool -x -n '__fish_zpool_using_command attach' -s o -d 'Pool property' -a '(__fish_zpool_list_device_properties)'
262end
263# The ideal behavior for attach is as follows:
264# - zpool attach [should list only pools]
265# - zpool attach <tank> [should list only devices already part of pool]
266# - zpool attach <tank> <da1> [should list only devices not already part of a/the pool]
267complete -c zpool -x -n '__fish_zpool_using_command attach; and __fish_is_nth_token 2' -d 'Pool to attach virtual device to' -a '(__fish_complete_zfs_pools)'
268complete -c zpool -x -n '__fish_zpool_using_command attach; and __fish_is_nth_token 3' -d 'Existing pool device to attach to' -a '(__fish_zpool_list_used_vdevs (__fish_nth_token 2))'
269# Generate a list of devices in the system modulo devices already part of an online zpool.
270# These latter can be forcefully added, so we only exclude them if we don't introspect the presence
271# of a `-f` argument to `zpool attach` (but still exclude any devices already part of the same pool
272# that we're attaching to, "obviously").
273complete -c zpool -x -n '__fish_zpool_using_command attach; and __fish_is_nth_token 4' -d 'Device to be attached' -a '(__fish_zpool_list_free_vdevs (__fish_seen_argument -s f && __fish_nth_token 2))'
274
275# clear completions
276if test $OS = FreeBSD
277    complete -c zpool -f -n '__fish_zpool_using_command clear' -s F -d 'Initiate recovery mode'
278    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'
279end
280complete -c zpool -x -n '__fish_zpool_using_command clear' -d 'Pool to clear errors on' -a '(__fish_complete_zfs_pools)'
281complete -c zpool -f -n '__fish_zpool_using_command clear' -d 'Virtual device to operate on' -a '(__fish_zpool_list_used_vdevs)'
282
283# create completions
284if test $OS = SunOS
285    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'
286else
287    complete -c zpool -f -n '__fish_zpool_using_command create' -s f -d 'Force use of virtual device'
288end
289complete -c zpool -f -n '__fish_zpool_using_command create' -s n -d 'Dry run, only display resulting configuration'
290complete -c zpool -f -n '__fish_zpool_using_command create' -s d -d 'Do not enable any feature on the new pool'
291complete -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)'
292complete -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)'
293complete -c zpool -r -n '__fish_zpool_using_command create' -s R -d 'Equivalent to "-o cachefile=none,altroot=ROOT"'
294complete -c zpool -x -n '__fish_zpool_using_command create' -s m -d 'Root filesystem mountpoint' -a 'legacy none'
295if __fish_is_openzfs
296    complete -c zpool -x -n '__fish_zpool_using_command create' -s t -d 'Set a different in-core pool name'
297end
298complete -c zpool -x -n '__fish_zpool_using_command create' -d 'Virtual device to add' -a '(__fish_zpool_complete_vdevs)'
299
300# destroy completions
301complete -c zpool -f -n '__fish_zpool_using_command destroy' -s f -d 'Force unmounting of all contained datasets'
302complete -c zpool -x -n '__fish_zpool_using_command destroy' -d 'Pool to destroy' -a '(__fish_complete_zfs_pools)'
303
304# detach completions
305complete -c zpool -x -n '__fish_zpool_using_command clear' -d 'Pool to detach device from' -a '(__fish_complete_zfs_pools)'
306complete -c zpool -x -n '__fish_zpool_using_command clear' -d 'Physical device to detach' -a '(__fish_zpool_list_used_vdevs)'
307
308# events completions
309if __fish_is_openzfs
310    complete -c zpool -f -n '__fish_zpool_using_command events' -s v -d 'Print verbose event information'
311    complete -c zpool -f -n '__fish_zpool_using_command events' -s H -d 'Print output in a machine-parsable format'
312    complete -c zpool -f -n '__fish_zpool_using_command events' -s f -d 'Output appended data as the log grows'
313    complete -c zpool -f -n '__fish_zpool_using_command events' -s c -d 'Clear all previous events'
314    complete -c zpool -f -n '__fish_zpool_using_command events' -d 'Pool to read events from' -a '(__fish_complete_zfs_pools)'
315end
316
317# export completions
318if __fish_is_openzfs
319    complete -c zpool -f -n '__fish_zpool_using_command export' -s a -d 'Export all pools'
320end
321complete -c zpool -f -n '__fish_zpool_using_command export' -s f -d 'Force unmounting of all contained datasets'
322complete -c zpool -x -n '__fish_zpool_using_command export' -d 'Pool to export' -a '(__fish_complete_zfs_pools)'
323
324# get completions
325complete -c zpool -f -n '__fish_zpool_using_command get' -s p -d 'Print parsable (exact) values for numbers'
326complete -c zpool -f -n '__fish_zpool_using_command get' -s H -d 'Print output in a machine-parsable format'
327if contains -- $OS FreeBSD SunOS
328    complete -c zpool -x -n '__fish_zpool_using_command get' -s o -d 'Fields to display' -a '(__fish_append , (__fish_zpool_list_get_fields))'
329end
330complete -c zpool -x -n '__fish_zpool_using_command get' -d 'Properties to get' -a '(__fish_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\tAll properties"))'
331complete -c zpool -x -n '__fish_zpool_using_command get' -d 'Pool to get properties of' -a '(__fish_complete_zfs_pools)'
332
333# history completions
334complete -c zpool -f -n '__fish_zpool_using_command history' -s i -d 'Also display internal events'
335complete -c zpool -f -n '__fish_zpool_using_command history' -s l -d 'Display log records using long format'
336complete -c zpool -f -n '__fish_zpool_using_command history' -d 'Pool to get command history of' -a '(__fish_complete_zfs_pools)'
337
338# import completions
339complete -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'
340complete -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'
341complete -c zpool -f -n '__fish_zpool_using_command import' -s D -d 'List or import destroyed pools only (requires -f for importation)'
342complete -c zpool -x -n '__fish_zpool_using_command import' -s o -d 'Mount properties for contained datasets' -a '(__fish_append , (__fish_complete_zfs_mountpoint_properties))'
343complete -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)'
344complete -c zpool -f -n '__fish_zpool_using_command import' -s f -d 'Force import'
345complete -c zpool -f -n '__fish_zpool_using_command import' -s F -d 'Recovery mode'
346complete -c zpool -f -n '__fish_zpool_using_command import' -s a -d 'Search for and import all pools found'
347complete -c zpool -f -n '__fish_zpool_using_command import' -s m -d 'Ignore missing log device (risk of loss of last changes)'
348complete -c zpool -r -n '__fish_zpool_using_command import' -s R -d 'Equivalent to "-o cachefile=none,altroot=ROOT"'
349complete -c zpool -f -n '__fish_zpool_using_command import' -s N -d 'Do not mount contained filesystems'
350complete -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'
351if __fish_is_openzfs
352    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)'
353    complete -c zpool -r -n '__fish_zpool_using_command import' -s T -d 'TXG to roll back to (implies -FX)'
354    complete -c zpool -f -n '__fish_zpool_using_command import' -s t -d 'Specify, as the last argument, a temporary pool name'
355end
356complete -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)'
357
358# iostat completions
359complete -c zpool -x -n '__fish_zpool_using_command iostat' -s T -d 'Display a timestamp using specified format'
360if __fish_is_openzfs
361    complete -c zpool -f -n '__fish_zpool_using_command iostat' -s g -d 'Display virtual device GUID instead of device name'
362    complete -c zpool -f -n '__fish_zpool_using_command iostat' -s L -d 'Resolve device path symbolic links'
363    complete -c zpool -f -n '__fish_zpool_using_command iostat' -s P -d 'Display device full path'
364    complete -c zpool -f -n '__fish_zpool_using_command iostat' -s y -d 'Omit statistics since boot'
365end
366complete -c zpool -f -n '__fish_zpool_using_command iostat' -s v -d 'Print verbose statistics'
367complete -c zpool -f -n '__fish_zpool_using_command iostat' -d 'Pool to retrieve I/O stats from' -a '(__fish_complete_zfs_pools)'
368
369# labelclear completions
370complete -c zpool -f -n '__fish_zpool_using_command labelclear' -s f -d 'Treat exported or foreign devices as inactive'
371complete -c zpool -x -n '__fish_zpool_using_command labelclear' -d 'Device to clear ZFS label information from' -a '(__fish_zpool_list_available_vdevs)'
372
373# list completions
374complete -c zpool -f -n '__fish_zpool_using_command list' -s H -d 'Print output in a machine-parsable format'
375if __fish_is_openzfs
376    complete -c zpool -f -n '__fish_zpool_using_command list' -s g -d 'Display virtual device GUID instead of device name'
377    complete -c zpool -f -n '__fish_zpool_using_command list' -s L -d 'Resolve device path symbolic links'
378end
379complete -c zpool -f -n '__fish_zpool_using_command list' -s P -d 'Display device full path'
380complete -c zpool -x -n '__fish_zpool_using_command list' -s T -d 'Display a timestamp using specified format'
381complete -c zpool -f -n '__fish_zpool_using_command list' -s v -d 'Print verbose statistics'
382complete -c zpool -x -n '__fish_zpool_using_command list' -s o -d 'Property to list' -a '(__fish_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))'
383complete -c zpool -f -n '__fish_zpool_using_command list' -d 'Pool to list properties of' -a '(__fish_complete_zfs_pools)'
384
385# offline completions
386complete -c zpool -f -n '__fish_zpool_using_command offline' -s t -d 'Temporarily offline'
387complete -c zpool -x -n '__fish_zpool_using_command offline' -d 'Pool to offline device from' -a '(__fish_complete_zfs_pools)'
388complete -c zpool -x -n '__fish_zpool_using_command offline' -d 'Physical device to offline' -a '(__fish_zpool_list_used_vdevs)'
389
390# online completions
391complete -c zpool -f -n '__fish_zpool_using_command online' -s e -d 'Expand the device to use all available space'
392complete -c zpool -x -n '__fish_zpool_using_command online' -d 'Pool to bring device back online on' -a '(__fish_complete_zfs_pools)'
393complete -c zpool -x -n '__fish_zpool_using_command online' -d 'Physical device to bring back online' -a '(__fish_zpool_list_used_vdevs)'
394
395# reguid completions
396complete -c zpool -x -n '__fish_zpool_using_command reguid' -d 'Pool which GUID is to be changed' -a '(__fish_complete_zfs_pools)'
397
398# remove completions
399complete -c zpool -x -n '__fish_zpool_using_command remove' -d 'Pool to remove device from' -a '(__fish_complete_zfs_pools)'
400complete -c zpool -x -n '__fish_zpool_using_command remove' -d 'Physical device to remove' -a '(__fish_zpool_list_used_vdevs)'
401
402# reopen completions
403complete -c zpool -x -n '__fish_zpool_using_command reopen' -d 'Pool which devices are to be reopened' -a '(__fish_complete_zfs_pools)'
404
405# replace completions (same semantics as attach)
406complete -c zpool -f -n '__fish_zpool_using_command replace' -s f -d 'Force use of virtual device'
407if __fish_is_openzfs
408    complete -c zpool -x -n '__fish_zpool_using_command replace' -s o -d 'Pool property' -a '(__fish_zpool_list_device_properties)'
409end
410complete -c zpool -x -n '__fish_zpool_using_command replace; and __fish_is_nth_token 2' -d 'Pool to replace device of' -a '(__fish_complete_zfs_pools)'
411complete -c zpool -x -n '__fish_zpool_using_command replace; and __fish_is_nth_token 3' -d 'Existing pool device to replace' -a '(__fish_zpool_list_used_vdevs (__fish_nth_token 2))'
412complete -c zpool -x -n '__fish_zpool_using_command replace; and __fish_is_nth_token 4' -d 'Replacement device' -a '(__fish_zpool_list_free_vdevs (__fish_seen_argument -s f && __fish_nth_token 2))'
413
414# scrub completions
415complete -c zpool -f -n '__fish_zpool_using_command scrub' -s s -d 'Stop scrubbing'
416if test $OS = SunOS
417    complete -c zpool -f -n '__fish_zpool_using_command scrub' -s p -d 'Pause scrubbing'
418end
419complete -c zpool -x -n '__fish_zpool_using_command scrub' -d 'Pool to start/stop scrubbing' -a '(__fish_complete_zfs_pools)'
420
421# set completions
422complete -c zpool -x -n '__fish_zpool_using_command set' -d 'Property to set' -a '(__fish_zpool_list_rw_properties)'
423complete -c zpool -x -n '__fish_zpool_using_command set' -d 'Pool which property is to be set' -a '(__fish_complete_zfs_pools)'
424
425# split completions
426if __fish_is_openzfs
427    complete -c zpool -f -n '__fish_zpool_using_command split' -s g -d 'Display virtual device GUID instead of device name'
428    complete -c zpool -f -n '__fish_zpool_using_command split' -s L -d 'Resolve device path symbolic links'
429    complete -c zpool -f -n '__fish_zpool_using_command split' -s P -d 'Display device full path'
430end
431complete -c zpool -f -n '__fish_zpool_using_command split' -s n -d 'Dry run: only display resulting configuration'
432complete -c zpool -r -n '__fish_zpool_using_command split' -s R -d 'Set altroot for newpool and automatically import it'
433complete -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)'
434if test $OS = FreeBSD
435    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_append , (__fish_complete_zfs_mountpoint_properties))'
436end
437complete -c zpool -x -n '__fish_zpool_using_command split' -d 'Pool to split' -a '(__fish_complete_zfs_pools)'
438
439# status completions
440if __fish_is_openzfs
441    complete -c zpool -f -n '__fish_zpool_using_command status' -s g -d 'Display virtual device GUID instead of device name'
442    complete -c zpool -f -n '__fish_zpool_using_command status' -s L -d 'Resolve device path symbolic links'
443    complete -c zpool -f -n '__fish_zpool_using_command status' -s P -d 'Display device full path'
444    complete -c zpool -f -n '__fish_zpool_using_command status' -s D -d 'Display deduplication histogram'
445else if test $OS = SunOS
446    complete -c zpool -f -n '__fish_zpool_using_command status' -s D -d 'Display deduplication histogram'
447end
448complete -c zpool -f -n '__fish_zpool_using_command status' -s v -d 'Verbose mode'
449complete -c zpool -f -n '__fish_zpool_using_command status' -s x -d 'Only display status for unhealthy or unavailable pools'
450complete -c zpool -x -n '__fish_zpool_using_command status' -s T -d 'Display a timestamp using specified format'
451complete -c zpool -f -n '__fish_zpool_using_command status' -d 'Pool which status is to be displayed' -a '(__fish_complete_zfs_pools)'
452
453# upgrade completions
454complete -c zpool -f -n '__fish_zpool_using_command upgrade' -s a -d 'Upgrade all eligible pools, enabling all supported features'
455complete -c zpool -f -n '__fish_zpool_using_command upgrade' -s v -d 'Display upgradeable ZFS versions'
456complete -c zpool -x -n '__fish_zpool_using_command upgrade' -s V -d 'Upgrade to the specified legacy version'
457complete -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)'