forked from OpenIndiana/openindiana-completions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg
267 lines (256 loc) · 8.33 KB
/
pkg
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
# OpenIndiana pkg(5) 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//,},"
_get_installed_packages()
{
# XXX: Lists only last part of package's FMRI, path walker is warranted
COMPREPLY=( $(compgen -W "$(pkg list -H $* | awk '{print $1}' | awk -F/ '{print $NF}')" -- "${cur}") )
}
_get_values()
{
local command="$1"
COMPREPLY=( $(compgen -W "$(pkg $command -H | awk '{print $1}')" -- "${cur}") )
}
_get_alternative_output_format()
{
COMPREPLY=( $(compgen -W "tsv json json-formatted" -- "${cur}") )
}
_pkg5()
{
local cur prev words cword line
line="${COMP_LINE}"
_init_completion || return
local cmds="list search info contents
update install uninstall history exact-install apply-hot-fix
verify fix revert
publisher set-publisher unset-publisher
mediator set-mediator unset-mediator facet change-facet variant change-variant
avoid unavoid freeze unfreeze
refresh rebuild-index purge-history
property set-property add-property-value unset-property remove-property-value
image-create dehydrate rehydrate help update-format version"
local cmd_opts=""
# Lookup for command
local special i
for (( i=1; i < $cword; i++ ))
do
if [[ ${words[i]} == @(list|search|info|contents|update|update-format|version|@(|un|exact-)install|history|verify|fix|revert|apply-hot-fix|@(|set-|unset-)publisher|@(|set-|unset-)mediator|@(|change-)facet|@(|change-)variant|@(|un)avoid|@(|un)freeze|refresh|rebuild-index|purge-history|@(|set-|unset-)property|@(add-|remove-)property-value|image-create|@(de|re)hydrate|help) ]]
then
special=${words[i]}
break
fi
done
if [[ -z "${special}" ]]
then
# Global options
local pkg_opts="-? --help -R"
if [[ "${prev}" == "-R" ]]
then
# Operate on the image rooted at dir
_cd
return
fi
else
# Command options
local cmd_opts_be="--no-be-activate
--no-backup-be --require-backup-be --backup-be-name
--deny-new-be --require-new-be --be-name"
case "${special}" in
apply-hot-fix)
cmd_opts="-n -v -q ${cmd_opts_be} -r"
if [[ "${prev}" == "-r" ]]; then cmd_opts="-z -Z"; fi
;;
change-facet|change-variant|exact-install|install)
cmd_opts="-n -v -q -C -g
--accept --licenses --no-index --no-refresh
${cmd_opts_be} -r
--sync-actuators --sync-actuators-timeout --reject"
if [[ "${prev}" == "-r" ]]; then cmd_opts="-z -Z"; fi
;;
contents)
cmd_opts="-H -m -r -a -g -o -s -t"
;;
dehydrate|rehydrate)
cmd_opts="-n -v -q -p"
;;
facet)
cmd_opts="-H -a -i -m -F"
;;
fix)
cmd_opts="-H -n -v -q ${cmd_opts_be} --accept --licenses"
;;
freeze)
cmd_opts="-n -c"
;;
history)
cmd_opts="-H -N -l -t -n -o"
;;
image-create)
cmd_opts="-F -P -U -f -z --force --full --partial --user --zone
-k -c --no-refresh --variant
-g --origin= -m --mirror= --facet -p --publisher"
;;
info)
cmd_opts="-l -q -r -g --license"
;;
list)
cmd_opts="-H -a -f -n -q -s -u -v -g --no-refresh"
;;
mediator)
# [-aH] [-F format] [mediator ...]
cmd_opts="-a -H -F"
;;
facet)
cmd_opts="-a -H -F"
;;
property)
cmd_opts="-H"
;;
publisher)
cmd_opts="-H -P -n -F"
;;
refresh)
cmd_opts="-q --full"
;;
revert)
cmd_opts="-n -v ${cmd_opts_be} --tagged"
;;
search)
cmd_opts="-H -I -a -f -l -p -r -o -s"
# XXX: complete the list of attributes per pkg(1) and pkg(5)
local pkg_attributes="pkg.fmri pkg.name pkg.human-version info.classification pkg.description
pkg.summary pkg.renamed pkg.obsolete"
# XXX: queries are not implemented
case ${cur} in
'"')
local realcur="${cur##\"}"
local pkg_query="depend"
compopt -o nospace
COMPREPLY=( $(compgen -W "${pkg_query}" -S ":" -- "${realcur}") )
return
;;
*depend:)
local realcur="${cur##:}"
local pkg_depend_type="conditional exclude group incorporate optional origin parent
require require-any"
COMPREPLY=( $(compgen -W "${pkg_depend_type}" -S ":" -- "${realcur}") )
return
;;
*)
local pkg_attributes_search="search.match search.match_type"
case "${prev}" in
-o|,)
compopt -o nospace
COMPREPLY=( $(compgen -W "${pkg_attributes} ${pk_attributes_search}" -- "${cur}") )
return
;;
*)
case "${cur}" in
,*)
# PKG attribute after comma
local realcur=${cur##,}
compopt -o nospace
COMPREPLY=( $(compgen -W "${pkg_attributes} ${pk_attributes_search}" -- "${realcur}") )
return
esac
;;
esac
;;
esac
;;
set-mediator|unset-mediator)
cmd_opts="-n -v -I -V ${cmd_opts_be}"
;;
set-publisher)
cmd_opts="-P -e -d -k -c
-g --add-origin= -G --remove-origin=
-m --add-mirror= -M --remove-mirror=
-p --enable --disable --no-refresh --reset-uuid
--non-sticky --sticky
--search-after= --search-before= --search-first
--approve-ca-cert= --revoke-ca-cert= --unset-ca-cert=
--set-property --unset-property
--add-property-value --remove-property-value
--proxy "
;;
unfreeze)
cmd_opts="-n"
;;
uninstall)
cmd_opts="-n -v -q -C -g --ignore-missing
--accept --licenses --no-index
${cmd_opts_be} -r
--sync-actuators --sync-actuators-timeout"
if [[ "${prev}" == "-r" ]]; then cmd_opts="-z -Z"; fi
;;
update)
cmd_opts="-n -v -q -C -g --accept --ignore-missing
--licenses --no-index --no-refresh
${cmd_opts_be} -r
--sync-actuators --sync-actuators-timeout --reject"
if [[ "${prev}" == "-r" ]]; then cmd_opts="-z -Z"; fi
;;
variant)
cmd_opts="-H -a -i -v -F"
;;
verify)
cmd_opts="-H -q -v"
;;
*)
;;
esac
fi
if [[ -z "${special}" ]]
then
if [[ "${cur}" == -* ]]
then
COMPREPLY=( $(compgen -W "${pkg_opts}" -- "${cur}") )
else
COMPREPLY=( $(compgen -W "${cmds}" -- "${cur}") )
fi
else
COMPREPLY=( $(compgen -W "${cmd_opts}" -- "${cur}") )
fi
if [[ "${cur}" != -* ]]
then
case ${special} in
apply-hot-fix)
local cur=${COMP_WORDS[COMP_CWORD]}
local IFS=$'\n'
compopt -o nospace
COMPREPLY=( $(compgen -o plusdirs -f -X '!*.p5p' -- $cur) )
;;
contents|list|freeze|unfreeze|update)
_get_installed_packages
;;
info)
[[ ${prev} == "-r" ]] && _get_installed_packages -a || _get_installed_packages
;;
install|exact-install)
_get_installed_packages -a
;;
publisher|refresh)
_get_values publisher
;;
property)
_get_values ${special}
;;
mediator|variant|facet)
[[ ${prev} == "-F" ]] && _get_alternative_output_format || _get_values ${special}
;;
dehydrate|rehydrate)
[[ ${prev} == "-p" ]] && _get_values publisher
;;
revert)
[[ ! ${line} =~ "--tagged" ]] && _cd
;;
esac
fi
} &&
complete -F _pkg5 +o default pkg
# ex: filetype=sh
# vim: tabstop=2 shiftwidth=2 expandtab smartindent