]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/systemd-nspawn
Merge pull request #9560 from mbiebl/uaccess-dev-kvm
[thirdparty/systemd.git] / shell-completion / bash / systemd-nspawn
CommitLineData
0d6883b6 1# systemd-nspawn(1) completion -*- shell-script -*-
7059062c 2# SPDX-License-Identifier: LGPL-2.1+
0d6883b6
TA
3#
4# This file is part of systemd.
5#
0d6883b6
TA
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
8c546358
CMC
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(){
e81eb287
ZJS
48 { cd /sys/class/net && echo *; } | \
49 while read -d' ' -r name; do
50 [[ "$name" != "lo" ]] && echo "$name"
51 done
8c546358
CMC
52}
53
0d6883b6
TA
54_systemd_nspawn() {
55 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
56 local i verb comps
57
58 local -A OPTS=(
86b4188d
YW
59 [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system --keep-unit -n --network-veth
60 -j -x --ephemeral -a --as-pid2 --private-users-chown -U'
61 [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro -M --machine
62 -S --slice -E --setenv -Z --selinux-context -L --selinux-apifs-context --register --network-interface --network-bridge
63 --personality -i --image --tmpfs --volatile --network-macvlan --kill-signal --template --notify-ready --root-hash
64 --chdir --pivot-root --property --private-users --network-namespace-path --network-ipvlan --network-veth-extra
65 --network-zone -p --port --system-call-filter --overlay --overlay-ro --settings'
0d6883b6
TA
66 )
67
68 _init_completion || return
69
70 if __contains_word "$prev" ${OPTS[ARG]}; then
71 case $prev in
6d94d993 72 --directory|-D|--template)
8c546358
CMC
73 compopt -o nospace
74 comps=$(compgen -S/ -A directory -- "$cur" )
0d6883b6
TA
75 ;;
76 --user|-u)
77 comps=$( __get_users )
78 ;;
86b4188d 79 --uuid|--root-hash)
0d6883b6
TA
80 comps=''
81 ;;
82 --capability)
83 comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO
84 CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN'
85 ;;
86 --drop-capability)
87 comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID
88 CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE
89 CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT
90 CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG'
91 ;;
92 --link-journal)
043a090d 93 comps='no auto guest try-guest host try-host'
0d6883b6
TA
94 ;;
95 --bind|--bind-ro)
8c546358
CMC
96 compopt -o nospace
97 comps=$(compgen -S/ -A directory -- "$cur" )
98 ;;
99 --tmpfs)
100 compopt -o nospace
101 comps=$(compgen -S/ -A directory -- "$cur" )
0d6883b6
TA
102 ;;
103 --machine|-M)
8c546358 104 comps=$( __get_machines )
0d6883b6
TA
105 ;;
106 --slice|-S)
107 comps=$( __get_slices )
108 ;;
86b4188d 109 --setenv|-E)
8c546358 110 comps=$( __get_env )
0d6883b6
TA
111 ;;
112 --selinux-context|-Z)
113 comps=''
114 ;;
115 --selinux-apifs-context|-L)
116 comps=''
117 ;;
118 --register)
119 comps='yes no'
120 ;;
121 --network-interface)
8c546358 122 comps=$(__get_interfaces)
0d6883b6
TA
123 ;;
124 --network-bridge)
125 comps=''
126 ;;
8c546358
CMC
127 --network-macvlan)
128 comps=''
129 ;;
0d6883b6
TA
130 --personality)
131 comps='x86 x86-64'
132 ;;
8c546358
CMC
133 --volatile)
134 comps='yes state no'
135 ;;
5ba85788 136 --image|-i)
8c546358 137 compopt -o nospace
5ba85788
TA
138 comps=$( compgen -A file -- "$cur" )
139 ;;
d5d841ff 140 --kill-signal)
18540892
ZJS
141 _signals
142 return
d5d841ff 143 ;;
14ca5c9c
AP
144 --notify-ready)
145 comps='yes no'
86b4188d
YW
146 ;;
147 --private-users)
148 comps='yes no pick'
149 ;;
150 --network-namespace-path)
151 comps=$( compgen -A file -- "$cur" )
152 ;;
153 --settings)
154 comps='yes no override trusted'
14ca5c9c 155 ;;
0d6883b6
TA
156 esac
157 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
158 return 0
159 fi
160
161 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
162}
163
164complete -F _systemd_nspawn systemd-nspawn