]> git.proxmox.com Git - systemd.git/blob - shell-completion/bash/systemd-nspawn
Imported Upstream version 231
[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 __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 { cd /sys/class/net && echo *; } | \
49 while read -d' ' -r name; do
50 [[ "$name" != "lo" ]] && echo "$name"
51 done
52 }
53
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=(
59 [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system --keep-unit --network-veth -j'
60 [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro -M --machine
61 -S --slice --setenv -Z --selinux-context -L --selinux-apifs-context --register --network-interface --network-bridge
62 --personality -i --image --tmpfs --volatile
63 --network-macvlan --kill-signal --template
64 --notify-ready'
65 )
66
67 _init_completion || return
68
69 if __contains_word "$prev" ${OPTS[ARG]}; then
70 case $prev in
71 --directory|-D|--template)
72 compopt -o nospace
73 comps=$(compgen -S/ -A directory -- "$cur" )
74 ;;
75 --user|-u)
76 comps=$( __get_users )
77 ;;
78 --uuid)
79 comps=''
80 ;;
81 --capability)
82 comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO
83 CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN'
84 ;;
85 --drop-capability)
86 comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID
87 CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE
88 CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT
89 CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG'
90 ;;
91 --link-journal)
92 comps='no auto guest try-guest host try-host'
93 ;;
94 --bind|--bind-ro)
95 compopt -o nospace
96 comps=$(compgen -S/ -A directory -- "$cur" )
97 ;;
98 --tmpfs)
99 compopt -o nospace
100 comps=$(compgen -S/ -A directory -- "$cur" )
101 ;;
102 --machine|-M)
103 comps=$( __get_machines )
104 ;;
105 --slice|-S)
106 comps=$( __get_slices )
107 ;;
108 --setenv)
109 comps=$( __get_env )
110 ;;
111 --selinux-context|-Z)
112 comps=''
113 ;;
114 --selinux-apifs-context|-L)
115 comps=''
116 ;;
117 --register)
118 comps='yes no'
119 ;;
120 --network-interface)
121 comps=$(__get_interfaces)
122 ;;
123 --network-bridge)
124 comps=''
125 ;;
126 --network-macvlan)
127 comps=''
128 ;;
129 --personality)
130 comps='x86 x86-64'
131 ;;
132 --volatile)
133 comps='yes state no'
134 ;;
135 --image|-i)
136 compopt -o nospace
137 comps=$( compgen -A file -- "$cur" )
138 ;;
139 --kill-signal)
140 _signals
141 return
142 ;;
143 --notify-ready)
144 comps='yes no'
145 return
146 ;;
147 esac
148 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
149 return 0
150 fi
151
152 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
153 }
154
155 complete -F _systemd_nspawn systemd-nspawn