]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-nspawn
Merge pull request #11180 from yuwata/update-bash-completion
[thirdparty/systemd.git] / shell-completion / bash / systemd-nspawn
1 # systemd-nspawn(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
3 #
4 # This file is part of systemd.
5 #
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 __get_machines() {
38 local a b
39 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
40 }
41
42 __get_env() {
43 local a
44 env | { while read a; do echo " ${a%%=*}"; done; };
45 }
46
47 __get_interfaces(){
48 local name
49 for name in $(cd /sys/class/net && ls); do
50 [[ "$name" != "lo" ]] && echo "$name"
51 done
52 }
53
54 __get_rlimit() {
55 local i
56 for i in $(systemd-nspawn --rlimit=help 2>/dev/null); do
57 echo " ${i}="
58 done
59 }
60
61 _systemd_nspawn() {
62 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
63 local i verb comps
64
65 local -A OPTS=(
66 [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system --keep-unit -n --network-veth
67 -j -x --ephemeral -a --as-pid2 --private-users-chown -U'
68 [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro -M --machine
69 -S --slice -E --setenv -Z --selinux-context -L --selinux-apifs-context --register --network-interface --network-bridge
70 --personality -i --image --tmpfs --volatile --network-macvlan --kill-signal --template --notify-ready --root-hash
71 --chdir --pivot-root --property --private-users --network-namespace-path --network-ipvlan --network-veth-extra
72 --network-zone -p --port --system-call-filter --overlay --overlay-ro --settings
73 --rlimit --hostname --no-new-privileges --oom-score-adjust --cpu-affinity --resolv-conf --timezone'
74 )
75
76 _init_completion || return
77
78 if __contains_word "$prev" ${OPTS[ARG]}; then
79 case $prev in
80 --directory|-D|--template)
81 compopt -o nospace
82 comps=$(compgen -S/ -A directory -- "$cur" )
83 ;;
84 --user|-u)
85 comps=$( __get_users )
86 ;;
87 --uuid|--root-hash)
88 comps=''
89 ;;
90 --capability)
91 comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO
92 CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN'
93 ;;
94 --drop-capability)
95 comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID
96 CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE
97 CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT
98 CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG'
99 ;;
100 --link-journal)
101 comps='no auto guest try-guest host try-host'
102 ;;
103 --bind|--bind-ro)
104 compopt -o nospace
105 comps=$(compgen -S/ -A directory -- "$cur" )
106 ;;
107 --tmpfs)
108 compopt -o nospace
109 comps=$(compgen -S/ -A directory -- "$cur" )
110 ;;
111 --machine|-M)
112 comps=$( __get_machines )
113 ;;
114 --slice|-S)
115 comps=$( __get_slices )
116 ;;
117 --setenv|-E)
118 comps=$( __get_env )
119 ;;
120 --selinux-context|-Z)
121 comps=''
122 ;;
123 --selinux-apifs-context|-L)
124 comps=''
125 ;;
126 --register)
127 comps='yes no'
128 ;;
129 --network-interface)
130 comps=$(__get_interfaces)
131 ;;
132 --network-bridge)
133 comps=''
134 ;;
135 --network-macvlan)
136 comps=''
137 ;;
138 --personality)
139 comps='x86 x86-64'
140 ;;
141 --volatile)
142 comps=$( systemd-nspawn --volatile=help 2>/dev/null )
143 ;;
144 --image|-i)
145 compopt -o nospace
146 comps=$( compgen -A file -- "$cur" )
147 ;;
148 --kill-signal)
149 _signals
150 return
151 ;;
152 --notify-ready)
153 comps='yes no'
154 ;;
155 --private-users)
156 comps='yes no pick'
157 ;;
158 --network-namespace-path)
159 comps=$( compgen -A file -- "$cur" )
160 ;;
161 --settings)
162 comps='yes no override trusted'
163 ;;
164 --rlimit)
165 comps=$( __get_rlimit )
166 ;;
167 --hostname)
168 comps=''
169 ;;
170 --no-new-privileges)
171 comps='yes no'
172 ;;
173 --oom-score-adjust)
174 comps=''
175 ;;
176 --cpu-affinity)
177 comps=''
178 ;;
179 --resolv-conf)
180 comps=$( systemd-nspawn --resolv-conf=help 2>/dev/null )
181 ;;
182 --timezone)
183 comps=$( systemd-nspawn --timezone=help 2>/dev/null )
184 ;;
185 esac
186 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
187 return 0
188 fi
189
190 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
191 }
192
193 complete -F _systemd_nspawn systemd-nspawn