Line 0
Link Here
|
|
|
1 |
#compdef zfs |
2 |
|
3 |
_zfs() { |
4 |
local context state line expl |
5 |
typeset -A opt_args |
6 |
local -a subcmds rw_properties rw_propnames ro_properties |
7 |
|
8 |
subcmds=( |
9 |
"create" "destroy" "clone" "promote" "rename" "snapshot" |
10 |
"rollback" "list" "set" "get" "inherit" "mount" "unmount" |
11 |
"share" "unshare" "send" "receive" "allow" "unallow" |
12 |
"upgrade" |
13 |
) |
14 |
|
15 |
ro_properties=( |
16 |
"name" "type" "creation" "used" "available" "referenced" |
17 |
"compressratio" "mounted" "origin" |
18 |
) |
19 |
|
20 |
# TODO: Be cleverer about what values can be set. Is there any way to |
21 |
# set the sorting for *size properties to false by default? |
22 |
rw_properties=( |
23 |
"aclinherit:value:(discard noallow secure passthrough)" |
24 |
"aclmode:value:(discard groupmask passthrough)" |
25 |
"atime:value:(on off)" |
26 |
"canmount:value:(on off)" |
27 |
"checksum:value:(on off fletcher2 fletcher4 sha256)" |
28 |
"compression:value:(on off lzjb gzip gzip-{1..9})" |
29 |
"copies:value:(1 2 3)" |
30 |
"devices:value:(on off)" |
31 |
"exec:value:(on off)" |
32 |
"mountpoint:value:{if [[ -prefix /* ]]; then _path_files -/; else _wanted mountpoints expl 'mountpoint (type \"/\" to start completing paths)' compadd legacy none; fi}" |
33 |
"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}" |
34 |
"readonly:value:(on off)" |
35 |
"recordsize:value:(512 1K 2K 4K 8K 16K 32K 64K 128K)" |
36 |
"reservation:value:" # <size>, "none" |
37 |
"setuid:value:(on off)" |
38 |
"shareiscsi:value:(on off)" # or "type=<type>" |
39 |
"sharenfs:value:(on off)" # or share(1M) options |
40 |
"snapdir:value:(hidden visible)" |
41 |
"version:value:(1 2 current)" |
42 |
"volblocksize:value:(512 1K 2K 4K 8K 16K 32K 64K 128K)" |
43 |
"volsize:value:" # <size> |
44 |
"xattr:value:(on off)" |
45 |
"zoned:value:(on off)" |
46 |
) |
47 |
|
48 |
rw_propnames=( ${rw_properties%%:*} ) |
49 |
|
50 |
if [[ $service == "zfs" ]]; then |
51 |
_arguments -C -A "-*" \ |
52 |
'-\?[Help]' \ |
53 |
'*::command:->subcmd' && return 0 |
54 |
|
55 |
if (( CURRENT == 1 )); then |
56 |
_wanted commands expl "zfs subcommand" compadd -a subcmds |
57 |
return |
58 |
fi |
59 |
service="$words[1]" |
60 |
curcontext="${curcontext%:*}=$service:" |
61 |
fi |
62 |
|
63 |
case $service in |
64 |
("create") |
65 |
_arguments -A "-*" \ |
66 |
'-p[Create parent datasets]' \ |
67 |
'-o[Set initial properties]:property:_values -s , "property" $rw_properties' \ |
68 |
- set1 \ |
69 |
':filesystem:' \ |
70 |
- set2 \ |
71 |
'-s[Create sparse volume]' \ |
72 |
'-b[Set volblocksize]:blocksize:' \ |
73 |
'-V[Set size]:size:' \ |
74 |
':volume:' |
75 |
;; |
76 |
|
77 |
("destroy") |
78 |
_arguments -A "-*" \ |
79 |
'-r[Recursively destroy all children]' \ |
80 |
'-R[Recursively destroy all dependents]' \ |
81 |
'-f[Force unmounts]' \ |
82 |
':filesystem/volume/snapshot:_zfs_dataset' |
83 |
;; |
84 |
|
85 |
("snapshot") |
86 |
_arguments -A "-*" \ |
87 |
'-r[Recursively snapshot all descendant datasets]' \ |
88 |
':filesystem/volume:_zfs_dataset -t fs -t vol -S@' |
89 |
;; |
90 |
|
91 |
("rollback") |
92 |
_arguments -A "-*" \ |
93 |
'-r[Recursively destroy more recent snapshots]' \ |
94 |
'-R[Recursively destroy more recent snapshots and clones]' \ |
95 |
'-f[Force unmounts]' \ |
96 |
':snapshot:_zfs_dataset -t snap' |
97 |
;; |
98 |
|
99 |
("clone") |
100 |
_arguments -A "-*" \ |
101 |
'-p[Create parent datasets]' \ |
102 |
# XXX needs to bail if there are no snapshots |
103 |
':snapshot:_zfs_dataset -t snap' \ |
104 |
':filesystem/volume:' |
105 |
;; |
106 |
|
107 |
("promote") |
108 |
# XXX complete only cloned filesystems |
109 |
_arguments \ |
110 |
':filesystem:_zfs_dataset -t fs' \ |
111 |
;; |
112 |
|
113 |
("rename") |
114 |
_arguments -A "-*" \ |
115 |
- set1 \ |
116 |
'-p[Create parent datasets]' \ |
117 |
':filesystem/volume/snapshot:_zfs_dataset' \ |
118 |
':filesystem/volume/snapshot:' \ |
119 |
- set2 \ |
120 |
'-r[Recursively rename snapshots of all descendent datasets]' \ |
121 |
':snapshot:_zfs_dataset -t snap' \ |
122 |
':snapshot:' |
123 |
;; |
124 |
|
125 |
("list") |
126 |
_arguments -A "-*" \ |
127 |
'-r[Recursively display children]' \ |
128 |
'-H[Scripting mode]' \ |
129 |
'-o[Properties to list]:property:_values -s , "property" $ro_properties $rw_propnames' \ |
130 |
'*-s[Sort key (ascending)]:property:_values "property" $ro_properties $rw_propnames' \ |
131 |
'*-S[Sort key (descending)]:property:_values "property" $ro_properties $rw_propnames' \ |
132 |
'-t[Dataset types to list]:dataset type:_values -s , "dataset type" filesystem snapshot volume' \ |
133 |
'*:filesystem/volume/snapshot:_zfs_dataset' |
134 |
;; |
135 |
|
136 |
("set") |
137 |
_arguments \ |
138 |
':property:_values -s , "property" $rw_properties' \ |
139 |
'*:filesystem/volume:_zfs_dataset -t fs -t vol' |
140 |
;; |
141 |
|
142 |
("get") |
143 |
_arguments -A "-*" \ |
144 |
"-r[Recursively display children's properties]" \ |
145 |
'-H[Scripting mode]' \ |
146 |
'-p[Display numbers exactly]' \ |
147 |
'-s[Specify sources]:source:_values -s , "source" local default inherited temporary none' \ |
148 |
'-o[Specify fields]:field:_values -s , "field" name property value source' \ |
149 |
':property:_values -s , "property" $ro_properties $rw_propnames all' \ |
150 |
'*:filesystem/volume/snapshot:_zfs_dataset' |
151 |
;; |
152 |
|
153 |
("inherit") |
154 |
_arguments -A "-*" \ |
155 |
'-r[Recursively inherit property for all children]' \ |
156 |
':property:_values -s , "property" $ro_properties $rw_properties' \ |
157 |
'*:filesystem/volume:_zfs_dataset -t fs -t vol' |
158 |
;; |
159 |
|
160 |
("mount") |
161 |
_arguments -A "-*" \ |
162 |
'-o[Mount options]:mount options:_values -s , "option" {,no}{devices,exec,setuid} ro rw' \ |
163 |
'-O[Overlay mount]' \ |
164 |
'-v[Report mount progress]' \ |
165 |
- set1 \ |
166 |
':filesystem:_zfs_dataset -t fs' \ |
167 |
- set2 \ |
168 |
'-a[Mount all available ZFS filesystems]' |
169 |
;; |
170 |
|
171 |
("unmount") |
172 |
_arguments -A "-*" \ |
173 |
- set1 \ |
174 |
'-f[Force unmount]' \ |
175 |
':filesystem:_zfs_dataset -t fs -t mtpt' \ |
176 |
- set2 \ |
177 |
'-a[Unmount all ZFS filesystems]' |
178 |
;; |
179 |
|
180 |
("share") |
181 |
_arguments -A "-*" \ |
182 |
- set1 \ |
183 |
'-a[Share all available ZFS filesystems]' \ |
184 |
- set2 \ |
185 |
':filesystem:_zfs_dataset -t fs' |
186 |
;; |
187 |
|
188 |
("unshare") |
189 |
_arguments -A "-*" \ |
190 |
- set1 \ |
191 |
'-a[Unshare all shared ZFS filesystems]' \ |
192 |
- set2 \ |
193 |
'-F[Force unshare]' \ |
194 |
':filesystem:_zfs_dataset -t fs -t mtpt' |
195 |
;; |
196 |
|
197 |
("send") |
198 |
_arguments -A "-*" \ |
199 |
'-i[Generate an incremental stream]:snapshot:_zfs_dataset -t snap' \ |
200 |
':snapshot:_zfs_dataset -t snap' |
201 |
;; |
202 |
|
203 |
("receive") |
204 |
_arguments -A "-*" \ |
205 |
'-v[Verbose]' \ |
206 |
'-n[Do not receive the stream]' \ |
207 |
'-F[Force a rollback if necessary]' \ |
208 |
- set1 \ |
209 |
':filesystem/volume/snapshot:_zfs_dataset' \ |
210 |
- set2 \ |
211 |
'-d[Set path prefix]:filesystem:_zfs_dataset -t fs' |
212 |
;; |
213 |
|
214 |
("allow"|"unallow") |
215 |
_message "unimplemented zfs subcommand: $service" |
216 |
;; |
217 |
|
218 |
("upgrade") |
219 |
_arguments -A "-*" \ |
220 |
- set1 \ |
221 |
'-v[Verbose]' \ |
222 |
- set2 \ |
223 |
'-a[Upgrade all filesystems on all pools]' \ |
224 |
'-r[Upgrade descendent filesystems, too]' \ |
225 |
'-V[Upgrade to specified version]:version:(1 2)' \ |
226 |
- set3 \ |
227 |
'-r[Upgrade descendent filesystems, too]' \ |
228 |
'-V[Upgrade to specified version]:version:(1 2)' \ |
229 |
':filesystem:_zfs_dataset -t fs' \ |
230 |
;; |
231 |
|
232 |
(*) |
233 |
_message "unknown zfs subcommand: $service" |
234 |
;; |
235 |
esac |
236 |
} |
237 |
|
238 |
_zfs "$@" |