]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-nspawn
bash completion: add -i/--image to nspawn
[thirdparty/systemd.git] / shell-completion / bash / systemd-nspawn
1 # systemd-nspawn(1) completion -*- shell-script -*-
2 #
3 # This file is part of systemd.
4 #
5 # Copyright 2014 Thomas H.P. Andersen
6 #
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
11 #
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
19
20 __contains_word() {
21 local w word=$1; shift
22 for w in "$@"; do
23 [[ $w = "$word" ]] && return
24 done
25 }
26
27 __get_users() {
28 local a b
29 loginctl list-users --no-legend --no-pager | { while read a b; do echo " $b"; done; };
30 }
31
32 __get_slices() {
33 local a b
34 systemctl list-units -t slice --no-legend --no-pager | { while read a b; do echo " $a"; done; };
35 }
36
37 _systemd_nspawn() {
38 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
39 local i verb comps
40
41 local -A OPTS=(
42 [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system --keep-unit --network-veth -j'
43 [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro -M --machine
44 -S --slice --setenv -Z --selinux-context -L --selinux-apifs-context --register --network-interface --network-bridge
45 --personality -i --image'
46 )
47
48 _init_completion || return
49
50 if __contains_word "$prev" ${OPTS[ARG]}; then
51 case $prev in
52 --directory|-D)
53 comps=$(compgen -A directory -- "$cur" )
54 ;;
55 --user|-u)
56 comps=$( __get_users )
57 ;;
58 --uuid)
59 comps=''
60 ;;
61 --capability)
62 comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO
63 CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN'
64 ;;
65 --drop-capability)
66 comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID
67 CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE
68 CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT
69 CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG'
70 ;;
71 --link-journal)
72 comps='no auto guest host'
73 ;;
74 --bind|--bind-ro)
75 comps=''
76 ;;
77 --machine|-M)
78 comps=''
79 ;;
80 --slice|-S)
81 comps=$( __get_slices )
82 ;;
83 --setenv)
84 comps=''
85 ;;
86 --selinux-context|-Z)
87 comps=''
88 ;;
89 --selinux-apifs-context|-L)
90 comps=''
91 ;;
92 --register)
93 comps='yes no'
94 ;;
95 --network-interface)
96 comps=''
97 ;;
98 --network-bridge)
99 comps=''
100 ;;
101 --personality)
102 comps='x86 x86-64'
103 ;;
104 --image|-i)
105 comps=$( compgen -A file -- "$cur" )
106 ;;
107 esac
108 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
109 return 0
110 fi
111
112 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
113 }
114
115 complete -F _systemd_nspawn systemd-nspawn