forked from OpenIndiana/openindiana-completions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zpool
423 lines (417 loc) · 13.7 KB
/
zpool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# OpenIndiana zpool(1M) completion -*- shell-script -*-
# ------------------------------------------------------------------------------
# Copyright (c) 2017, Aurelien Larcher <[email protected]>
# Copyright (c) 2018, Michal Nowak <[email protected]>
# Bash-completion does not handle custom wordbreaks so comma-separated values
# cannot be implemented without this.
COMP_WORDBREAKS="${COMP_WORDBREAKS//,},"
_zpool()
{
local cur prev words cword
_init_completion -n : || return
local cmds="create destroy add remove labelclear checkpoint list iostat status online offline clear reopen attach detach replace split initialize scrub import export upgrade reguid history get set"
local cmd_opts=""
local zpool_properties="allocated bootsize capacity expandsize fragmentation free freeing health guid size unsupported@ altroot readonly=on readonly=off autoexpand=on autoexpand=off autoreplace=on autoreplace=off bootfs= cachefile= comment= dedupditto= delegation= failmode=wait failmode=continue failmode=panic feature@ listsnapshots=on listsnapshots=off version="
# Lookup for command
local special i
for (( i=1; i < $cword; i++ ))
do
if [[ ${words[i]} == @(create|destroy|add|remove|labelclear|checkpoint|list|iostat|status|online|offline|clear|reopen|attach|detach|replace|split|initialize|scrub|import|export|upgrade|reguid|history|get|set) ]]
then
special=${words[i]}
break
fi
done
if [[ -z "${special}" ]]
then
if [[ "${cur}" == -* ]]
then
COMPREPLY=( $(compgen -W "-?" -- "${cur}") )
return
else
COMPREPLY=( $(compgen -W "${cmds}" -- "${cur}") )
return
fi
else
# Command options
if [[ "${cur}" == -* ]]
then
case "${special}" in
create)
# create [-fnd] [-B] [-o property=value] ...
# [-O file-system-property=value] ...
# [-m mountpoint] [-R root] <pool> <vdev> ...
cmd_opts="-f -n -d -B -o -O -m -R"
;;
destroy)
# destroy [-f] <pool>
cmd_opts="-f"
;;
add)
# add [-fn] <pool> <vdev> ...
cmd_opts="-f -n"
;;
remove)
# remove [-np] pool device...
# remove -s pool
cmd_opts="-n -p -s"
;;
labelclear)
# labelclear [-f] device
cmd_opts="-f"
;;
checkpoint)
# checkpoint [-d, --discard]
cmd_opts="-d --discard"
;;
list)
# list [-Hp] [-o property[,...]] [-T d|u] [pool] ... [interval [count]]
cmd_opts="-H -p -o -T"
;;
iostat)
# iostat [-v] [-T d|u] [pool] ... [interval [count]]
cmd_opts="-v -T"
;;
status)
# status [-vx] [-T d|u] [pool] ... [interval [count]]
cmd_opts="-v -x -T"
;;
online)
# online <pool> <device> ...
cmd_opts=""
;;
offline)
# offline [-t] <pool> <device> ...
cmd_opts="-t"
;;
clear)
# clear [-nF] <pool> [device]
cmd_opts="-n -F"
;;
reopen)
# reopen <pool>
cmd_opts=""
;;
attach)
# attach [-f] <pool> <device> <new-device>
cmd_opts="-f"
;;
detach)
# detach <pool> <device>
cmd_opts=""
;;
replace)
# replace [-f] <pool> <device> [new-device]
cmd_opts="-f"
;;
split)
# split [-n] [-R altroot] [-o mntopts]
# [-o property=value] <pool> <newpool> [<device> ...]
cmd_opts="-n -R -o"
;;
initialize)
# initialize [-cs] pool [device...]
cmd_opts="-c -s"
;;
scrub)
# scrub [-s | -p] <pool> ...
cmd_opts="-s -p"
;;
import)
# import [-d dir] [-D]
# import [-d dir | -c cachefile] [-F [-n]] <pool | id>
# import [-o mntopts] [-o property=value] ...
# [-d dir | -c cachefile] [-D] [-f] [-m] [-N] [-R root] [-F [-n]] -a
# import [-o mntopts] [-o property=value] ...
# [-d dir | -c cachefile] [-D] [-f] [-m] [-N] [-R root] [-F [-n]]
# <pool | id> [newpool]
cmd_opts="-d -D -c -F -n -o -f -m -N -R -a"
;;
export)
# export [-f] <pool> ...
cmd_opts="-f"
;;
upgrade)
# upgrade
# upgrade -v
# upgrade [-V version] <-a | pool ...>
cmd_opts="-v -V -a"
;;
reguid)
# reguid <pool>
cmd_opts=""
;;
history)
# history [-il] [<pool>] ...
cmd_opts="-i -l"
;;
get)
# get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
cmd_opts="-H -p -o"
;;
set)
# set <property=value> <pool>
cmd_opts=""
;;
esac
COMPREPLY=( $(compgen -W "${cmd_opts}" -- "${cur}") )
return
else
case "${special}" in
create)
# create [-fnd] [-B] [-o property=value] ...
# O file-system-property=value] ...
# m mountpoint] [-R root] <pool> <vdev> ...
case "${prev}" in
-o)
# Zpool property
compopt -o nospace
COMPREPLY=( $(compgen -W "$(zpool get 2>&1 | nawk '$2 == "YES" {print $1}')" -S '=' -- "${cur}") )
return
;;
esac
;;
destroy)
# destroy [-f] <pool>
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
add)
# add [-fn] <pool> <vdev> ...
case "${prev}" in
add|-f|-n)
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
*)
COMPREPLY=( $(compgen -W "$(zpool list -Hv ${prev} | nawk 'NR>1 && $1 !~ "raid|mirror" { print $1 }')" -- "${cur}") )
return
;;
esac
;;
remove)
# remove [-np] pool device...
# remove -s pool
case "${prev}" in
remove|-n|-p|-s)
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
*)
COMPREPLY=( $(compgen -W "$(zpool list -Hv ${prev} | nawk 'NR>1 && $1 !~ "raid|mirror" { print $1 }')" -- "${cur}") )
return
;;
esac
;;
labelclear)
# labelclear [-f] device
# TODO: List devices?
;;
checkpoint)
# checkpoint [-d, --discard] pool
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
;;
list|iostat|status)
# list [-Hp] [-o property[,...]] [-T d|u] [pool] ... [interval [count]]
# iostat [-v] [-T d|u] [pool] ... [interval [count]]
# status [-vx] [-T d|u] [pool] ... [interval [count]]
case "${prev}" in
-o)
if [[ "${special}" != "list" ]]; then return; fi;
# Zpool property
compopt -o nospace
COMPREPLY=( $(compgen -W "$(zpool get 2>&1 | nawk '$2 == "NO" || $2 == "YES" {print $1}')" -- "${cur}") )
return
;;
-T)
COMPREPLY=( $(compgen -W "d u" -- "${cur}") )
return
;;
*)
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
esac
;;
online)
# online <pool> <device> ...
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
offline)
# offline [-t] <pool> <device> ...
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
clear)
# clear [-nF] <pool> [device]
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
reopen)
# reopen <pool>
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
attach)
# attach [-f] <pool> <device> <new-device>
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
;;
detach)
# detach <pool> <device>
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
replace)
# replace [-f] <pool> <device> [new-device]
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
split)
# split [-n] [-R altroot] [-o mntopts]
# [-o property=value] <pool> <newpool> [<device> ...]
case "${prev}" in
-o)
COMPREPLY=( $(compgen -W "$zpool_properties" -- "${cur}") )
return
;;
*)
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
esac
;;
initialize)
# initialize [-cs] pool [device...]
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
scrub)
# scrub [-s | -p] <pool> ...
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
import)
# import [-d dir] [-D]
# import [-d dir | -c cachefile] [-F [-n]] <pool | id>
# import [-o mntopts] [-o property=value] ...
# [-d dir | -c cachefile] [-D] [-f] [-m] [-N] [-R root] [-F [-n]] -a
# import [-o mntopts] [-o property=value] ...
# [-d dir | -c cachefile] [-D] [-f] [-m] [-N] [-R root] [-F [-n]]
# <pool | id> [newpool]
case "${prev}" in
-d|-c)
_cd
return
;;
-o)
COMPREPLY=( $(compgen -W "$zpool_properties" -- "${cur}") )
return
;;
*)
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
esac
;;
export)
# export [-f] <pool> ...
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
upgrade)
# upgrade
# upgrade -v
# upgrade [-V version] <-a | pool ...>
case "${prev}" in
-V)
COMPREPLY=( $(compgen -W "$(zpool upgrade -v | nawk '/^ [0-9]/ {print $1}')" -- "${cur}") )
return
;;
-a|-v)
return
;;
*)
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
esac
;;
reguid)
# reguid <pool>
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
history)
# history [-il] [<pool>] ...
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
get)
# get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
case "${prev}" in
-o)
# Zpool property field
compopt -o nospace
COMPREPLY=( $(compgen -W "name property value source all" -- "${cur}") )
return
;;
,)
# Check whether the field or property list is being completed
local pprev="${COMP_WORDS[COMP_CWORD-2]}"
if [[ ${pprev} == @(name|property|value|source|all) ]]
then
# Zpool property field
local realcur=${cur##*,}
compopt -o nospace
COMPREPLY=( $(compgen -W "name property value source all" -- "${realcur}") )
return
else
# Zpool property
local realcur=${cur##*,}
compopt -o nospace
COMPREPLY=( $(compgen -W "$(zpool get 2>&1 | nawk '$2 == "NO" || $2 == "YES" {print $1}')" -- "${realcur}") )
return
fi
;;
get|-*|name|property|value|source|all)
if [[ ${cur} == ,* ]]
then
# Zpool property field
local realcur=${cur##*,}
compopt -o nospace
COMPREPLY=( $(compgen -W "name property value source all" -- "${realcur}") )
return
fi
# Zpool property
compopt -o nospace
COMPREPLY=( $(compgen -W "$(zpool get 2>&1 | nawk '$2 == "NO" || $2 == "YES" {print $1}')" -- "${cur}") )
return
;;
*)
if [[ ${cur} == ,* ]]
then
# Zpool property
local realcur=${cur##*,}
compopt -o nospace
COMPREPLY=( $(compgen -W "$(zpool get 2>&1 | nawk '$2 == "NO" || $2 == "YES" {print $1}')" -- "${realcur}") )
return
fi
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
esac
return
;;
set)
# set <property=value> <pool>
COMPREPLY=( $(compgen -W "$(zpool list -H -o name)" -- "${cur}") )
return
;;
esac
fi
fi
} &&
complete -F _zpool +o default zpool
# ex: filetype=sh
# vim: tabstop=2 shiftwidth=2 expandtab smartindent