]>
Commit | Line | Data |
---|---|---|
0d6883b6 TA |
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 | ||
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(){ | |
48 | cut -f 1 -d ' ' /proc/net/dev | tail -n +3 | tr -s '\n' | tr -d ':' | xargs | |
49 | } | |
50 | ||
0d6883b6 TA |
51 | _systemd_nspawn() { |
52 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
53 | local i verb comps | |
54 | ||
55 | local -A OPTS=( | |
56 | [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system --keep-unit --network-veth -j' | |
57 | [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro -M --machine | |
58 | -S --slice --setenv -Z --selinux-context -L --selinux-apifs-context --register --network-interface --network-bridge | |
8c546358 CMC |
59 | --personality -i --image --tmpfs --volatile |
60 | --network-macvlan' | |
0d6883b6 TA |
61 | ) |
62 | ||
63 | _init_completion || return | |
64 | ||
65 | if __contains_word "$prev" ${OPTS[ARG]}; then | |
66 | case $prev in | |
67 | --directory|-D) | |
8c546358 CMC |
68 | compopt -o nospace |
69 | comps=$(compgen -S/ -A directory -- "$cur" ) | |
0d6883b6 TA |
70 | ;; |
71 | --user|-u) | |
72 | comps=$( __get_users ) | |
73 | ;; | |
74 | --uuid) | |
75 | comps='' | |
76 | ;; | |
77 | --capability) | |
78 | comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO | |
79 | CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN' | |
80 | ;; | |
81 | --drop-capability) | |
82 | comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID | |
83 | CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE | |
84 | CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT | |
85 | CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG' | |
86 | ;; | |
87 | --link-journal) | |
043a090d | 88 | comps='no auto guest try-guest host try-host' |
0d6883b6 TA |
89 | ;; |
90 | --bind|--bind-ro) | |
8c546358 CMC |
91 | compopt -o nospace |
92 | comps=$(compgen -S/ -A directory -- "$cur" ) | |
93 | ;; | |
94 | --tmpfs) | |
95 | compopt -o nospace | |
96 | comps=$(compgen -S/ -A directory -- "$cur" ) | |
0d6883b6 TA |
97 | ;; |
98 | --machine|-M) | |
8c546358 | 99 | comps=$( __get_machines ) |
0d6883b6 TA |
100 | ;; |
101 | --slice|-S) | |
102 | comps=$( __get_slices ) | |
103 | ;; | |
104 | --setenv) | |
8c546358 | 105 | comps=$( __get_env ) |
0d6883b6 TA |
106 | ;; |
107 | --selinux-context|-Z) | |
108 | comps='' | |
109 | ;; | |
110 | --selinux-apifs-context|-L) | |
111 | comps='' | |
112 | ;; | |
113 | --register) | |
114 | comps='yes no' | |
115 | ;; | |
116 | --network-interface) | |
8c546358 | 117 | comps=$(__get_interfaces) |
0d6883b6 TA |
118 | ;; |
119 | --network-bridge) | |
120 | comps='' | |
121 | ;; | |
8c546358 CMC |
122 | --network-macvlan) |
123 | comps='' | |
124 | ;; | |
0d6883b6 TA |
125 | --personality) |
126 | comps='x86 x86-64' | |
127 | ;; | |
8c546358 CMC |
128 | --volatile) |
129 | comps='yes state no' | |
130 | ;; | |
5ba85788 | 131 | --image|-i) |
8c546358 | 132 | compopt -o nospace |
5ba85788 TA |
133 | comps=$( compgen -A file -- "$cur" ) |
134 | ;; | |
0d6883b6 TA |
135 | esac |
136 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
137 | return 0 | |
138 | fi | |
139 | ||
140 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
141 | } | |
142 | ||
143 | complete -F _systemd_nspawn systemd-nspawn |