-
Notifications
You must be signed in to change notification settings - Fork 10
/
_xattr
46 lines (43 loc) · 1.98 KB
/
_xattr
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
#compdef xattr
# zsh completion for OSX's xattr
#
# usage: xattr [-l] [-r] [-s] [-v] [-x] file [file ...]
# xattr -p [-l] [-r] [-s] [-v] [-x] attr_name file [file ...]
# xattr -w [-r] [-s] [-x] attr_name attr_value file [file ...]
# xattr -d [-r] [-s] attr_name file [file ...]
# xattr -c [-r] [-s] file [file ...]
#
# The first form lists the names of all xattrs on the given file(s).
# The second form (-p) prints the value of the xattr attr_name.
# The third form (-w) sets the value of the xattr attr_name to the string attr_value.
# The fourth form (-d) deletes the xattr attr_name.
# The fifth form (-c) deletes (clears) all xattrs.
#
# options:
# -h: print this help
# -l: print long format (attr_name: attr_value and hex output has offsets and
# ascii representation)
# -r: act recursively
# -s: act on the symbolic link itself rather than what the link points to
# -v: also print filename (automatic with -r and with multiple files)
# -x: attr_value is represented as a hex string for input and output
local extra
local -a _xattr_options
_xattr_options=(
'(-w -d -c)-p[prints the value of the xattr attr_name]'
'(-p -d -c -v)-w[sets the value of the xattr attr_name to the string attr_value]'
'(-p -w -c -l -v -x)-d[deletes the xattr attr_name]'
'(-p -w -d -l -v -x)-c[deletes (clears) all xattrs]'
'(- *)-h[print help]'
'-l[print long format (attr_name: attr_value and hex output has offsets and ascii representation)]'
'-r[act recursively]'
'-s[act on the symbolic link itself rather than what the link points to]'
'-v[also print filename (automatic with -r and with multiple files)]'
'-x[attr_value is represented as a hex string for input and output]'
)
if [[ $words =~ 'p|d' ]]; then
[[ ${words[$(($#words-1))]} =~ "^-" ]] && extra='(-)*:attribut name'
elif [[ $words =~ 'w' ]]; then
[[ ${words[$(($#words-2))]} =~ "^-" || ${words[$(($#words-1))]} =~ "^-" ]] && extra=(':attribut name' '(-):attribut value')
fi
_arguments -s $_xattr_options ${extra:-'(-)*: :_files'}