]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/systemd-nspawn
Merge pull request #8962 from floppym/issue8905
[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#
6# Copyright 2014 Thomas H.P. Andersen
7#
8# systemd is free software; you can redistribute it and/or modify it
9# under the terms of the GNU Lesser General Public License as published by
10# the Free Software Foundation; either version 2.1 of the License, or
11# (at your option) any later version.
12#
13# systemd is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public License
19# along with systemd; If not, see <http://www.gnu.org/licenses/>.
20
21__contains_word() {
22 local w word=$1; shift
23 for w in "$@"; do
24 [[ $w = "$word" ]] && return
25 done
26}
27
28__get_users() {
29 local a b
30 loginctl list-users --no-legend --no-pager | { while read a b; do echo " $b"; done; };
31}
32
33__get_slices() {
34 local a b
35 systemctl list-units -t slice --no-legend --no-pager | { while read a b; do echo " $a"; done; };
36}
37
8c546358
CMC
38__get_machines() {
39 local a b
40 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
41}
42
43__get_env() {
44 local a
45 env | { while read a; do echo " ${a%%=*}"; done; };
46}
47
48__get_interfaces(){
e81eb287
ZJS
49 { cd /sys/class/net && echo *; } | \
50 while read -d' ' -r name; do
51 [[ "$name" != "lo" ]] && echo "$name"
52 done
8c546358
CMC
53}
54
0d6883b6
TA
55_systemd_nspawn() {
56 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
57 local i verb comps
58
59 local -A OPTS=(
86b4188d
YW
60 [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system --keep-unit -n --network-veth
61 -j -x --ephemeral -a --as-pid2 --private-users-chown -U'
62 [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro -M --machine
63 -S --slice -E --setenv -Z --selinux-context -L --selinux-apifs-context --register --network-interface --network-bridge
64 --personality -i --image --tmpfs --volatile --network-macvlan --kill-signal --template --notify-ready --root-hash
65 --chdir --pivot-root --property --private-users --network-namespace-path --network-ipvlan --network-veth-extra
66 --network-zone -p --port --system-call-filter --overlay --overlay-ro --settings'
0d6883b6
TA
67 )
68
69 _init_completion || return
70
71 if __contains_word "$prev" ${OPTS[ARG]}; then
72 case $prev in
6d94d993 73 --directory|-D|--template)
8c546358
CMC
74 compopt -o nospace
75 comps=$(compgen -S/ -A directory -- "$cur" )
0d6883b6
TA
76 ;;
77 --user|-u)
78 comps=$( __get_users )
79 ;;
86b4188d 80 --uuid|--root-hash)
0d6883b6
TA
81 comps=''
82 ;;
83 --capability)
84 comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO
85 CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN'
86 ;;
87 --drop-capability)
88 comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID
89 CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE
90 CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT
91 CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG'
92 ;;
93 --link-journal)
043a090d 94 comps='no auto guest try-guest host try-host'
0d6883b6
TA
95 ;;
96 --bind|--bind-ro)
8c546358
CMC
97 compopt -o nospace
98 comps=$(compgen -S/ -A directory -- "$cur" )
99 ;;
100 --tmpfs)
101 compopt -o nospace
102 comps=$(compgen -S/ -A directory -- "$cur" )
0d6883b6
TA
103 ;;
104 --machine|-M)
8c546358 105 comps=$( __get_machines )
0d6883b6
TA
106 ;;
107 --slice|-S)
108 comps=$( __get_slices )
109 ;;
86b4188d 110 --setenv|-E)
8c546358 111 comps=$( __get_env )
0d6883b6
TA
112 ;;
113 --selinux-context|-Z)
114 comps=''
115 ;;
116 --selinux-apifs-context|-L)
117 comps=''
118 ;;
119 --register)
120 comps='yes no'
121 ;;
122 --network-interface)
8c546358 123 comps=$(__get_interfaces)
0d6883b6
TA
124 ;;
125 --network-bridge)
126 comps=''
127 ;;
8c546358
CMC
128 --network-macvlan)
129 comps=''
130 ;;
0d6883b6
TA
131 --personality)
132 comps='x86 x86-64'
133 ;;
8c546358
CMC
134 --volatile)
135 comps='yes state no'
136 ;;
5ba85788 137 --image|-i)
8c546358 138 compopt -o nospace
5ba85788
TA
139 comps=$( compgen -A file -- "$cur" )
140 ;;
d5d841ff 141 --kill-signal)
18540892
ZJS
142 _signals
143 return
d5d841ff 144 ;;
14ca5c9c
AP
145 --notify-ready)
146 comps='yes no'
86b4188d
YW
147 ;;
148 --private-users)
149 comps='yes no pick'
150 ;;
151 --network-namespace-path)
152 comps=$( compgen -A file -- "$cur" )
153 ;;
154 --settings)
155 comps='yes no override trusted'
14ca5c9c 156 ;;
0d6883b6
TA
157 esac
158 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
159 return 0
160 fi
161
162 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
163}
164
165complete -F _systemd_nspawn systemd-nspawn