0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# systemd-nspawn(1) completion -*- shell-script -*-
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# This file is part of systemd.
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# Copyright 2014 Thomas H.P. Andersen
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# systemd is free software; you can redistribute it and/or modify it
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# under the terms of the GNU Lesser General Public License as published by
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# the Free Software Foundation; either version 2.1 of the License, or
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# (at your option) any later version.
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# systemd is distributed in the hope that it will be useful, but
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# WITHOUT ANY WARRANTY; without even the implied warranty of
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# General Public License for more details.
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# You should have received a copy of the GNU Lesser General Public License
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen# along with systemd; If not, see <http://www.gnu.org/licenses/>.
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen__contains_word() {
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen local w word=$1; shift
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen for w in "$@"; do
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen [[ $w = "$word" ]] && return
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen__get_users() {
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen loginctl list-users --no-legend --no-pager | { while read a b; do echo " $b"; done; };
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen__get_slices() {
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen systemctl list-units -t slice --no-legend --no-pager | { while read a b; do echo " $a"; done; };
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo__get_machines() {
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo env | { while read a; do echo " ${a%%=*}"; done; };
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo__get_interfaces(){
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo cut -f 1 -d ' ' /proc/net/dev | tail -n +3 | tr -s '\n' | tr -d ':' | xargs
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen_systemd_nspawn() {
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen local i verb comps
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen local -A OPTS=(
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system --keep-unit --network-veth -j'
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro -M --machine
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen -S --slice --setenv -Z --selinux-context -L --selinux-apifs-context --register --network-interface --network-bridge
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo --personality -i --image --tmpfs --volatile
d5d841ff9daac420993f2a0bbed3ace610c9b22dEvgeny Vereshchagin --network-macvlan --kill-signal'
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen _init_completion || return
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen if __contains_word "$prev" ${OPTS[ARG]}; then
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen case $prev in
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --directory|-D)
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo compopt -o nospace
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo comps=$(compgen -S/ -A directory -- "$cur" )
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen comps=$( __get_users )
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --capability)
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN'
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --drop-capability)
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG'
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --link-journal)
043a090d7d866cd21669e871969899a568ef5f8cEvgeny Vereshchagin comps='no auto guest try-guest host try-host'
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --bind|--bind-ro)
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo compopt -o nospace
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo comps=$(compgen -S/ -A directory -- "$cur" )
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo compopt -o nospace
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo comps=$(compgen -S/ -A directory -- "$cur" )
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --machine|-M)
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo comps=$( __get_machines )
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen comps=$( __get_slices )
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo comps=$( __get_env )
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --selinux-context|-Z)
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --selinux-apifs-context|-L)
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen comps='yes no'
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --network-interface)
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo comps=$(__get_interfaces)
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --network-bridge)
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo --network-macvlan)
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen --personality)
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen comps='x86 x86-64'
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo comps='yes state no'
8c5463585df633ca302824559888b62de5b4ba20Carlos Morata Castillo compopt -o nospace
5ba85788ab3b934db90b42508c7a7892277b5e94Thomas Hindoe Paaboel Andersen comps=$( compgen -A file -- "$cur" )
d5d841ff9daac420993f2a0bbed3ace610c9b22dEvgeny Vereshchagin --kill-signal)
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersen COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
0d6883b6a870b66c8c70e43695d22de96aab68e7Thomas Andersencomplete -F _systemd_nspawn systemd-nspawn