1 #compdef zpool |
|
2 # Synced with the Nevada build 131 man page |
|
3 |
|
4 _zpool() { |
|
5 local context state line expl |
|
6 local -a subcmds fields ro_props rw_props versions create_properties_dataset |
|
7 |
|
8 subcmds=( |
|
9 create destroy add remove list iostat status online |
|
10 offline clear attach detach replace scrub import export |
|
11 upgrade history get set split |
|
12 ) |
|
13 |
|
14 versions=( |
|
15 ${${${(M)"${(f)$(zpool upgrade -v)}":#[[:space:]]#<->*}##[[:space:]]}%%[[:space:]]*} |
|
16 ) |
|
17 |
|
18 ro_props=( |
|
19 "all[All properties]" |
|
20 "alloc[Space allocated]" |
|
21 "capacity[Space used (percentage)]" |
|
22 "dedupratio[Deduplication ratio]" |
|
23 "free[Space unallocated]" |
|
24 "guid[Unique identifier]" |
|
25 "health[Health status]" |
|
26 "size[Total size]" |
|
27 ) |
|
28 |
|
29 rw_props=( |
|
30 "altroot[Alternate root directory]:value:" |
|
31 "autoexpand[Automatic pool expansion]:value:(on off)" |
|
32 "autoreplace[Automatic device replacement]:value:(on off)" |
|
33 "bootfs[Default bootable dataset]:value:" |
|
34 "cachefile[Pool configuration cache file location]:value:" |
|
35 "delegation[Delegated administration]:value:(on off)" |
|
36 "failmode[Failure-mode behavior]:value:(wait continue panic)" |
|
37 "listsnaps[Show snapshots in 'zfs list']:value:(on off)" |
|
38 "version[Pool version]:version:($versions)" |
|
39 ) |
|
40 |
|
41 fields=( ${ro_props%%:*} ${rw_props%%:*} ) |
|
42 |
|
43 create_properties_dataset=( |
|
44 "aclinherit:value:(discard noallow restricted passthrough passthrough-x)" |
|
45 "aclmode:value:(discard groupmask passthrough)" |
|
46 "atime:value:(on off)" |
|
47 "canmount:value:(on off noauto)" |
|
48 "checksum:value:(on off fletcher2 fletcher4 sha256)" |
|
49 "compression:value:(on off lzjb gzip gzip-{1..9})" |
|
50 "copies:value:(1 2 3)" |
|
51 "devices:value:(on off)" |
|
52 "exec:value:(on off)" |
|
53 "groupquota@:value:" # TODO: complete group=size|none |
|
54 "logbias:value:(latency throughput)" |
|
55 "mountpoint:path, 'legacy', or 'none':{if [[ -prefix /* ]]; then _path_files -/; else _wanted mountpoints expl 'mountpoint (type \"/\" to start completing paths)' compadd legacy none; fi}" |
|
56 "nbmand:value:(on off)" |
|
57 "primarycache:value:(all none metadata)" |
|
58 "quota:number or 'none':{if [[ -prefix [0-9]## ]]; then _message -e 'number'; elif [[ $PREFIX == quota= ]]; then _wanted none expl 'number or none' compadd none; else _wanted none expl 'quota' compadd none; fi}" |
|
59 "readonly:value:(on off)" |
|
60 "recordsize:value:(512 1K 2K 4K 8K 16K 32K 64K 128K)" |
|
61 "refquota:number or 'none':{if [[ -prefix [0-9]## ]]; then _message -e 'number'; elif [[ $PREFIX == refquota= ]]; then _wanted none expl 'number or none' compadd none; else _wanted none expl 'refquota' compadd none; fi}" |
|
62 "refreservation:number or 'none':{if [[ -prefix [0-9]## ]]; then _message -e 'number'; elif [[ $PREFIX == refreservation= ]]; then _wanted none expl 'number or none' compadd none; else _wanted none expl 'refreservation' compadd none; fi}" |
|
63 "reservation:value:{if [[ -prefix [0-9]## ]]; then _message -e 'number'; elif [[ $PREFIX == reservation= ]]; then _wanted none expl 'number or none' compadd none; else _wanted none expl 'reservation' compadd none; fi}" |
|
64 "secondarycache:value:(all none metadata)" |
|
65 "setuid:value:(on off)" |
|
66 "shareiscsi:value:(on off type=disk)" |
|
67 "sharenfs:value:(on off)" # or share(1M) options |
|
68 "sharesmb:value:(on off)" # or sharemgr(1M) options |
|
69 "snapdir:value:(hidden visible)" |
|
70 "userquota@:value:" # TODO: complete user=size|none |
|
71 "version:value:(1 2 current)" |
|
72 "volsize:value:" # <size> |
|
73 "vscan:value:(on off)" |
|
74 "xattr:value:(on off)" |
|
75 "zoned:value:(on off)" |
|
76 ) |
|
77 |
|
78 if [[ $service == "zpool" ]]; then |
|
79 _arguments -C -A "-*" \ |
|
80 '-\?[Help]' \ |
|
81 '*::command:->subcmd' && return 0 |
|
82 |
|
83 if (( CURRENT == 1 )); then |
|
84 _wanted commands expl "zpool subcommand" compadd -a subcmds |
|
85 return |
|
86 fi |
|
87 service="$words[1]" |
|
88 curcontext="${curcontext%:*}=$service:" |
|
89 fi |
|
90 |
|
91 case $service in |
|
92 (clear) |
|
93 _arguments -A "-*" \ |
|
94 '-F[Discard transactions to allow pool opening]' \ |
|
95 '-n[With -F, check if discarding transactions would work' \ |
|
96 ':pool name:_zfs_pool' \ |
|
97 '*:virtual device:_files' |
|
98 ;; |
|
99 |
|
100 (create) |
|
101 # TODO: investigate better vdev handling |
|
102 _arguments -A "-*" \ |
|
103 '-o[Set pool property at creation time]:property:_values -s , "property" $rw_props' \ |
|
104 '-O[Set dataset property at creation time]:property:_values -s , "property" $create_properties_dataset' \ |
|
105 '-f[Force use of in-use devices]' \ |
|
106 '-n[Display configuration without creating pool]' \ |
|
107 '-R[Use alternate root]:alternate root:_files -/' \ |
|
108 '-m[Set mountpoint for root dataset]:mountpoint:' \ |
|
109 ':pool name:' \ |
|
110 '*:virtual device:_files' |
|
111 ;; |
|
112 |
|
113 (destroy) |
|
114 _arguments -A "-*" \ |
|
115 '-f[Force active datasets to be unmounted]' \ |
|
116 ':pool name:_zfs_pool' |
|
117 ;; |
|
118 |
|
119 (add) |
|
120 _arguments -A "-*" \ |
|
121 '-f[Force use of in-use devices]' \ |
|
122 '-n[Display configuration without modifying pool]' \ |
|
123 ':pool name:_zfs_pool' \ |
|
124 '*:virtual device:_files' |
|
125 ;; |
|
126 |
|
127 (list) |
|
128 _arguments \ |
|
129 '-H[Scripted mode]' \ |
|
130 '-o[Fields to list]:field:_values -s , "field" $fields' \ |
|
131 '::pool name:_zfs_pool' |
|
132 ;; |
|
133 |
|
134 (iostat) |
|
135 _arguments -A "-*" \ |
|
136 '-T[timestamp]:value:(u d)' \ |
|
137 '-v[Verbose statistics]' \ |
|
138 '*::pool name:_zfs_pool' \ |
|
139 '::interval:' \ |
|
140 '::count:' |
|
141 ;; |
|
142 |
|
143 (status) |
|
144 _arguments -A "-*" \ |
|
145 '-v[Verbose information]' \ |
|
146 '-x[Show only unhealthy pools]' \ |
|
147 '*::pool name:_zfs_pool' |
|
148 ;; |
|
149 |
|
150 (offline) |
|
151 _arguments -A "-*" \ |
|
152 '-t[Offline until next reboot]' \ |
|
153 ':pool name:_zfs_pool' \ |
|
154 '*:virtual device:_files' |
|
155 ;; |
|
156 |
|
157 (online) |
|
158 _arguments \ |
|
159 ':pool name:_zfs_pool' \ |
|
160 '*:virtual device:_files' |
|
161 ;; |
|
162 |
|
163 (attach) |
|
164 # TODO: first device should choose first from existing. |
|
165 _arguments \ |
|
166 '-f[Force attach, even if in use]' \ |
|
167 ':pool name:_zfs_pool' \ |
|
168 ':virtual device:_files' \ |
|
169 ':virtual device:_files' |
|
170 ;; |
|
171 |
|
172 (detach) |
|
173 _arguments \ |
|
174 ':pool name:_zfs_pool' \ |
|
175 ':virtual device:_files' |
|
176 ;; |
|
177 |
|
178 (replace) |
|
179 _arguments -A "-*" \ |
|
180 '-f[Force attach, even if in use]' \ |
|
181 ':pool name:_zfs_pool' \ |
|
182 ':virtual device:_files' \ |
|
183 '::virtual device:_files' |
|
184 ;; |
|
185 |
|
186 (scrub) |
|
187 _arguments -A "-*" \ |
|
188 '-s[Stop scrubbing]' \ |
|
189 '*:pool name:_zfs_pool' |
|
190 ;; |
|
191 |
|
192 (export) |
|
193 _arguments -A "-*" \ |
|
194 '-f[Forcefully unmount all datasets]' \ |
|
195 '*:pool name:_zfs_pool' |
|
196 ;; |
|
197 |
|
198 (import) |
|
199 # TODO: -o should complete mount options, too |
|
200 _arguments -A "-*" \ |
|
201 '-D[Destroyed pools]' \ |
|
202 '(-d)*-c[Use cache file]:cache file:_files' \ |
|
203 '(-c)*-d[Search for devices or files in directory]:directory:_files -/' \ |
|
204 '-f[Force import]' \ |
|
205 '-R[Alternate root]:alternate root:_files -/' \ |
|
206 '-o[Set pool or dataset property]:property:_values -s , "property" $create_properties_dataset $rw_props' \ |
|
207 - set1 \ |
|
208 '*:pool name or id:_zfs_pool' \ |
|
209 '::new pool name:' \ |
|
210 - set2 \ |
|
211 '-a[All pools]' |
|
212 ;; |
|
213 |
|
214 (get) |
|
215 _arguments -A "-*" \ |
|
216 ':property:_values -s , "property" $fields' \ |
|
217 '*:pool name:_zfs_pool' |
|
218 ;; |
|
219 |
|
220 (set) |
|
221 _arguments -A "-*" \ |
|
222 ':property:_values -s , "property" $rw_props' \ |
|
223 '*:pool name:_zfs_pool' |
|
224 ;; |
|
225 |
|
226 (split) |
|
227 _arguments -A "-*" \ |
|
228 '-R[Alternate root]:alternate root:_files -/' \ |
|
229 '-n[Display config without splitting]::' \ |
|
230 '-o[Set pool or dataset property]:property:_values -s , "property" $create_properties_dataset $rw_props' \ |
|
231 '*:pool name or id:_zfs_pool' \ |
|
232 '::new pool name:' \ |
|
233 '*:device:_files -/' |
|
234 |
|
235 (upgrade) |
|
236 _arguments -A "-*" \ |
|
237 - set1 \ |
|
238 '-v[Display ZFS versions and descriptions]' \ |
|
239 - set2 \ |
|
240 "-V[Upgrade to given version]:version:($versions)" \ |
|
241 '-a[Upgrade all pools]' \ |
|
242 '*:pool name:_zfs_pool' |
|
243 ;; |
|
244 |
|
245 (history) |
|
246 _arguments -A "-*" \ |
|
247 '-i[Display internal events]' \ |
|
248 '-l[Long format]' \ |
|
249 '*:pool name:_zfs_pool' |
|
250 ;; |
|
251 |
|
252 (*) |
|
253 _message "unknown zpool subcommand: $service" |
|
254 ;; |
|
255 esac |
|
256 } |
|
257 |
|
258 _zpool "$@" |
|