Debian Codegraph @

share/bash-completion/container

raw
1 # Open Infrastructure: compute-tools
2
3 # Copyright (C) 2014-2026 Daniel Baumann <[email protected]>
4 #
5 # SPDX-License-Identifier: GPL-3.0+
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20 _container()
21 {
22 local cur prev cmd opts
23 COMPREPLY=()
24 cur="${COMP_WORDS[COMP_CWORD]}"
25 prev="${COMP_WORDS[COMP_CWORD-1]}"
26
27 if [ ${COMP_CWORD} -gt 0 ]
28 then
29 cmd="${COMP_WORDS[1]}"
30 fi
31
32 if [ "${prev}" = "--" ]
33 then
34 compopt -o bashdefault
35 COMPREPLY=( $(compgen -c -- $cur) )
36 return 0
37 fi
38
39 case "${cmd}" in
40 auto)
41 opts="-f --force -s --start -t --stop"
42 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
43 return 0
44 ;;
45
46 build|b)
47 case "${prev}" in
48 -n|--name)
49 opts="$(cd /etc/compute-tools/debconf 2>/dev/null && ls *.cfg */*.cfg 2>/dev/null | sed -e 's|.*/||g' -e 's|.cfg$||g')"
50 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
51 return 0
52 ;;
53
54 -s|--script)
55 opts="$(cd /usr/share/compute-tools/build-scripts && find -maxdepth 1 -not -type d -and -not -name 'default' -and -not -name 'debconf' -and -not -name '*.d' -printf '%P\n' | sort)"
56 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
57 return 0
58 ;;
59
60 *)
61 opts="-n --name -c --capability -d --drop-capability -s --script -v --verbose -b --bind --bind-ro"
62 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
63 return 0
64 ;;
65 esac
66 ;;
67
68 console)
69 case "${prev}" in
70 -n|--name)
71 opts="$(container list -s -f shell)"
72 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
73 return 0
74 ;;
75
76 *)
77 opts="-n --name"
78 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
79 return 0
80 ;;
81 esac
82 ;;
83
84 enter|run)
85 case "${prev}" in
86 -n|--name)
87 opts="$(container list -s -f shell)"
88 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
89 return 0
90 ;;
91
92 *)
93 opts="-n --name"
94 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
95 return 0
96 ;;
97 esac
98 ;;
99
100 get|g)
101 case "${prev}" in
102 -n|--name)
103 opts="$(cd /etc/compute-tools/debconf 2>/dev/null && ls *.cfg */*.cfg 2>/dev/null | sed -e 's|.*/||g' -e 's|.cfg$||g')"
104 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
105 return 0
106 ;;
107
108 -s|--script)
109 opts="$(cd /usr/share/compute-tools/get-scripts && find -maxdepth 1 -not -type d -and -not -name 'default' -and -not -name 'debconf' -and -not -name '*.d' -printf '%P\n' | sort)"
110 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
111 return 0
112 ;;
113
114 *)
115 opts="-n --name -c --capability -d --drop-capability -s --script -v --verbose -b --bind --bind-ro"
116 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
117 return 0
118 ;;
119 esac
120 ;;
121
122 info)
123 case "${prev}" in
124 -n|--name)
125 opts="$(container list -t -f shell)"
126 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
127 return 0
128 ;;
129
130 *)
131 opts="--status --os --ip"
132 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
133 return 0
134 ;;
135 esac
136 ;;
137
138 key)
139 case "${prev}" in
140 -a|--add)
141 opts="$(cd /usr/share/compute-tools/keys 2>/dev/null && ls *.pub 2>/dev/null | sed -e 's|.*/||g' -e 's|.pub$||g')"
142 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
143 return 0
144 ;;
145
146 -r|--remove)
147 opts="$(gpg --homedir /etc/compute-tools/keys --list-keys | grep ^uid | sed -e 's|.*<||' -e 's|>||')"
148 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
149 return 0
150 ;;
151
152 *)
153 opts="-a --add -r --remove -l --list"
154 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
155 return 0
156 ;;
157 esac
158 ;;
159
160 limit)
161 case "${prev}" in
162 -n|--name)
163 opts="$(container list -a -f shell)"
164 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
165 return 0
166 ;;
167
168 *)
169 opts="-n --name --blockio-device-weight --blockio-read-bandwidth -b --blockio-weight --blockio-write-bandwidth -c --cpu-quota --cpu-shares -m --memory-limit -t --tasks-max"
170 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
171 return 0
172 ;;
173 esac
174 ;;
175
176 list|ls)
177 case "${prev}" in
178 -h|--host)
179 opts="true false $(hostname -f 2> /dev/null || hostname)"
180 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
181 return 0
182 ;;
183
184 -f|--format)
185 opts="cli csv json shell sh yaml xml"
186 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
187 return 0
188 ;;
189
190 *)
191 opts="-a --all -f --format -h --host -o --other -s --started -t --stopped"
192 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
193 return 0
194 ;;
195 esac
196 ;;
197
198 log)
199 case "${prev}" in
200 -d|--date)
201 opts="$(if ls /var/log/compute-tools/container.log-*.gz > /dev/null 2>&1;
202 then \
203 zcat /var/log/compute-tools/container.log-*.gz | awk '{ print $1 }' | sort -u; \
204 fi; \
205 if [ -e /var/log/compute-tools/container.log ]; \
206 then \
207 awk '{ print $1 }' /var/log/compute-tools/container.log | sort -u; \
208 fi) \
209 today yesterday"
210 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
211 return 0
212 ;;
213
214 -n|--name)
215 opts="$(if ls /var/log/compute-tools/container.log-*.gz > /dev/null 2>&1;
216 then \
217 zgrep -E '(\-n|\-\-name) ' /var/log/compute-tools/container.log-*.gz | sed -e 's|.*-n ||' -e 's|.*--name ||' -e 's| .*$||' | sort -u; \
218 fi; \
219 if [ -e /var/log/compute-tools/container.log ]; \
220 then \
221 grep -E '(\-n|\-\-name) ' /var/log/compute-tools/container.log | sed -e 's|.*-n ||' -e 's|.*--name ||' -e 's| .*$||' | sort -u; \
222 fi)"
223 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
224 return 0
225 ;;
226
227 *)
228 opts="-d --date -n --name"
229 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
230 return 0
231 ;;
232 esac
233 ;;
234
235 move|mv)
236 case "${prev}" in
237 -o|--old)
238 opts="$(container list -t -f shell)"
239 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
240 return 0
241 ;;
242
243 *)
244 opts="-f --force -n --new -o --old"
245 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
246 return 0
247 ;;
248 esac
249 ;;
250
251 remove|rm)
252 case "${prev}" in
253 -n|--name)
254 opts="$(container list -t -f shell)"
255 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
256 return 0
257 ;;
258
259 *)
260 opts="-n --name -f --force -i --interactive -k --kill"
261 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
262 return 0
263 ;;
264 esac
265 ;;
266
267 rebuild|rb)
268 case "${prev}" in
269 -n|--name)
270 opts="$(container list -f shell)"
271 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
272 return 0
273 ;;
274
275 *)
276 opts="-n --name -f --force -v --verbose"
277 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
278 return 0
279 ;;
280 esac
281 ;;
282
283 restart|rs)
284 case "${prev}" in
285 -n|--name)
286 opts="$(container list -s -f shell)"
287 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
288 return 0
289 ;;
290
291 *)
292 opts="-n --name"
293 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
294 return 0
295 ;;
296 esac
297 ;;
298
299 start|s)
300 case "${prev}" in
301 -n|--name)
302 opts="$(container list -t -f shell)"
303 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
304 return 0
305 ;;
306
307 *)
308 opts="-n --name -v --verbose"
309 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
310 return 0
311 ;;
312 esac
313 ;;
314
315 status|st)
316 case "${prev}" in
317 -n|--name)
318 opts="$(container list -f shell)"
319 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
320 return 0
321 ;;
322
323 *)
324 opts="-n --name"
325 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
326 return 0
327 ;;
328 esac
329 ;;
330
331 stop|t)
332 case "${prev}" in
333 -n|--name)
334 opts="$(container list -s -f shell)"
335 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
336 return 0
337 ;;
338
339 *)
340 opts="-n --name -f --force"
341 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
342 return 0
343 ;;
344 esac
345 ;;
346
347 top)
348 opts="-d --delay"
349 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
350 return 0
351 ;;
352
353 update|u)
354 case "${prev}" in
355 -n|--name)
356 opts="$(container list -s -f shell)"
357 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
358 return 0
359 ;;
360
361 *)
362 opts="-n --name -f --full-upgrade -r --autoremove -p --purge --y --yes"
363 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
364 return 0
365 ;;
366 esac
367 ;;
368
369 version|ver)
370 return 0
371 ;;
372
373 *)
374 local commands=$(cd /usr/libexec/container 2>/dev/null && find * -type f -print)
375 COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
376 return 0
377 ;;
378 esac
379
380 compopt -o filenames
381 COMPREPLY=( $(compgen -f -- $cur) )
382 return 0
383 }
384
385 complete -F _container container cnt