]> git.proxmox.com Git - systemd.git/blob - shell-completion/bash/machinectl
Enable seccomp support on powerpc, ppc64el, and s390x
[systemd.git] / shell-completion / bash / machinectl
1 # machinectl(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_machines() {
28 local a b
29 (machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \
30 { while read a b; do echo " $a"; done; } | sort -u;
31 }
32
33 _machinectl() {
34 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
35 local i verb comps
36
37 local -A OPTS=(
38 [STANDALONE]='--all -a --full --help -h --no-ask-password --no-legend --no-pager --version'
39 [ARG]='--host -H --kill-who -M --machine --property -p --signal -s'
40 )
41
42 local -A VERBS=(
43 [STANDALONE]='list list-images pull-tar pull-raw pull-dkr import-tar import-raw export-tar export-raw list-transfers cancel-transfer'
44 [MACHINES]='status show start login shell enable disable poweroff reboot terminate kill copy-to copy-from image-status show-image clone rename read-only remove set-limit'
45 )
46
47 _init_completion || return
48
49 for ((i=0; i <= COMP_CWORD; i++)); do
50 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
51 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
52 verb=${COMP_WORDS[i]}
53 break
54 fi
55 done
56
57 if __contains_word "$prev" ${OPTS[ARG]}; then
58 case $prev in
59 --signal|-s)
60 comps=$(compgen -A signal)
61 ;;
62 --kill-who)
63 comps='all leader'
64 ;;
65 --host|-H)
66 comps=$(compgen -A hostname)
67 ;;
68 --machine|-M)
69 comps=$( __get_machines )
70 ;;
71 --property|-p)
72 comps=''
73 ;;
74 esac
75 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
76 return 0
77 fi
78
79 if [[ "$cur" = -* ]]; then
80 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
81 return 0
82 fi
83
84 if [[ -z $verb ]]; then
85 comps=${VERBS[*]}
86
87 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
88 comps=''
89
90 elif __contains_word "$verb" ${VERBS[MACHINES]}; then
91 comps=$( __get_machines )
92 fi
93
94 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
95 return 0
96 }
97
98 complete -F _machinectl machinectl