-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautopkg
executable file
·256 lines (224 loc) · 5.74 KB
/
autopkg
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
# Bash completion for autopkg
# by Tony Williams, [email protected]
# version 0.5
# 14/05/2017
__autopkgcomp_words_include() {
local i=1
while [[ "$i" -lt "$COMP_CWORD" ]]
do
if [[ "${COMP_WORDS[i]}" = "$1" ]]
then
return 0
fi
i="$((++i))"
done
return 1
}
__autopkgcomp() {
# break $1 on space, tab, and newline characters,
# and turn it into a newline separated list of words
local list s sep=$'\n' IFS=$' '$'\t'$'\n'
local cur="${COMP_WORDS[COMP_CWORD]}"
for s in $1
do
__autopkgcomp_words_include "$s" && continue
list="$list$s$sep"
done
IFS="$sep"
COMPREPLY=($(compgen -W "$list" -- "$cur"))
}
__autopkgcomp_recipes() {
# build a list of recipes
local recipes="$(autopkg list-recipes)"
COMPREPLY=($(compgen -W "$recipes" -- "$cur"))
}
__autopkgcomp_repos() {
# build a list of the repos - returns the URL form
local repolist="$(for r in `autopkg repo-list`; do expr $r : '.*(\(.*\))'; done)"
local repos
while read -r line; do
# remove empty lines
if [[ -n $line ]]; then
repos="$repos $line"
fi
# when the repo url starts with github.com, also add the path
if [[ $line == "https://github.com/"* ]]; then
repos="$repos ${line:19}"
fi
# when the repo url starts with github.com/autopkg, then add just the name
if [[ $line == "https://github.com/autopkg/"* ]]; then
repos="$repos ${line:27}"
fi
done <<< "$repolist"
COMPREPLY=($(compgen -W "$repos" -- "$cur"))
}
# one function for each autopkg command
# some do nothing, just included for neatness and possible use in an expansion
_autopkg_audit() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --search-dir= --override-dir= --recipe-list= --plist"
return
;;
esac
__autopkgcomp_recipes
}
_autopkg_help() {
return
}
_autopkg_info() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --directory= --override-dir="
return
;;
esac
__autopkgcomp_recipes
}
_autopkg_install() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --pre --post --ignoreparent-trust-verification-errors
--check --report-plist= --verbose --search-dir= --override-dir="
return
;;
esac
# we can only install recipes ending in `.install`
local installable="$(autopkg list-recipes | grep .install)"
COMPREPLY=($(compgen -W "$installable" -- "$cur"))
}
_autopkg_list_processors() {
return
}
_autopkg_list_recipes() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --with-identifiers --with-path --plist --show-all
--search-dir= --override-dir="
return
;;
esac
}
_autopkg_make_override() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --force --search-dir= --override-dir= --name="
return
;;
esac
__autopkgcomp_recipes
}
_autopkg_new_recipe() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --parent-identifier= --identifier="
return
;;
esac
}
_autopkg_processor_info() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --recipe= --search-dir= --override-dir= --name="
return
;;
esac
}
_autopkg_repo-add() {
return
}
_autopkg_repo-delete() {
__autopkgcomp_repos
}
_autopkg_repo-list() {
return
}
_autopkg_repo-add() {
return
}
_autopkg_repo-update() {
__autopkgcomp_repos
}
_autopkg_run() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --pre= --post= --ignoreparent-trust-verification-errors
--check --recipe-list= --pkg= --report-plist= --verbose
--search-dir= --override-dir= --quiet"
return
;;
esac
__autopkgcomp_recipes
}
_autopkg_search() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --recipe --search-dir --override-dir --name"
return
;;
esac
}
_autopkg_update_trust_info() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --search-dir --override-dir"
return
;;
esac
}
_autopkg_verify_trust_info() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
__autopkgcomp "--help --recipe-list --verbose --search-dir --override-dir"
return
;;
esac
}
_autopkg() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ "$COMP_CWORD" = "1" ]] # we are matching the command
then
opts="audit help info install list-processors list-recipes \
make-override new-recipe processor-info repo-add repo-delete repo-list \
repo-update run search update-trust-info verify-trust-info version"
COMPREPLY=( $(compgen -W "${opts}" ${cur}) )
return 0
fi
cmd="${COMP_WORDS[1]}"
case "$cmd" in
audit) _autopkg_audit ;;
help) _autopkg_help ;;
info) _autopkg_info ;;
list-processors) _autopkg_list_processors ;;
list-recipes) _autopkg_list_recipes ;;
make-override) _autopkg_make_override ;;
new-recipe) _new_recipe ;;
processor-info) _autopkg_processor_info ;;
repo-add) _autopkg_repo-add ;;
repo-delete) _autopkg_repo-delete ;;
repo-list) _autopkg_repo-list ;;
repo-update) _autopkg_repo-update ;;
run) _autopkg_run ;;
search) _autopkg_search ;;
update-trust-info) _autopkg_update_trust_info ;;
verify-trust-info) _autopkg_verify_trust_info ;;
version) _autopkg_version ;;
install) _autopkg_install ;;
*)
esac
}
complete -o bashdefault -o default -F _autopkg autopkg