]>
Commit | Line | Data |
---|---|---|
e56056e9 | 1 | # machinectl(1) completion -*- shell-script -*- |
7059062c | 2 | # SPDX-License-Identifier: LGPL-2.1+ |
e56056e9 TA |
3 | # |
4 | # This file is part of systemd. | |
5 | # | |
e56056e9 TA |
6 | # systemd is free software; you can redistribute it and/or modify it |
7 | # under the terms of the GNU Lesser General Public License as published by | |
8 | # the Free Software Foundation; either version 2.1 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # systemd is distributed in the hope that it will be useful, but | |
12 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU Lesser General Public License | |
17 | # along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | __contains_word() { | |
843cfcb1 ZJS |
20 | local w word=$1; shift |
21 | for w in "$@"; do | |
22 | [[ $w = "$word" ]] && return | |
23 | done | |
e56056e9 TA |
24 | } |
25 | ||
26 | __get_machines() { | |
843cfcb1 ZJS |
27 | local a b |
28 | (machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \ | |
29 | { while read a b; do echo " $a"; done; } | sort -u; | |
e56056e9 TA |
30 | } |
31 | ||
32 | _machinectl() { | |
843cfcb1 ZJS |
33 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} |
34 | local i verb comps | |
e56056e9 | 35 | |
843cfcb1 ZJS |
36 | local -A OPTS=( |
37 | [STANDALONE]='--all -a -l --full --help -h --no-ask-password --no-legend --no-pager --version --value | |
38 | --mkdir --read-only --force -q --quiet' | |
39 | [ARG]='--host -H --kill-who -M --machine --property -p --signal -s --uid -E --setenv -n --lines | |
40 | -o --output --verify --format --max-addresses' | |
41 | ) | |
e56056e9 | 42 | |
843cfcb1 ZJS |
43 | local -A VERBS=( |
44 | [STANDALONE]='list list-images clean pull-tar pull-raw list-transfers cancel-transfer import-fs' | |
45 | [MACHINES]='status show start stop login shell enable disable poweroff reboot terminate kill bind | |
46 | copy-to copy-from image-status show-image clone rename read-only remove set-limit | |
47 | export-tar export-raw' | |
48 | [FILE]='import-tar import-raw' | |
49 | ) | |
e56056e9 | 50 | |
843cfcb1 | 51 | _init_completion || return |
e56056e9 | 52 | |
843cfcb1 ZJS |
53 | for ((i=0; i <= COMP_CWORD; i++)); do |
54 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && | |
55 | ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then | |
56 | verb=${COMP_WORDS[i]} | |
57 | break | |
e56056e9 | 58 | fi |
843cfcb1 | 59 | done |
e56056e9 | 60 | |
843cfcb1 ZJS |
61 | if __contains_word "$prev" ${OPTS[ARG]}; then |
62 | case $prev in | |
63 | --signal|-s) | |
64 | _signals | |
65 | return | |
66 | ;; | |
67 | --kill-who) | |
68 | comps='all leader' | |
69 | ;; | |
70 | --host|-H) | |
71 | comps=$(compgen -A hostname) | |
72 | ;; | |
73 | --machine|-M) | |
74 | comps=$( __get_machines ) | |
75 | ;; | |
76 | --property|-p) | |
77 | comps='' | |
78 | ;; | |
79 | --output|-o) | |
80 | comps=$( machinectl --output=help 2>/dev/null ) | |
81 | ;; | |
82 | --verify) | |
83 | comps=$( machinectl --verify=help 2>/dev/null ) | |
84 | ;; | |
85 | --format) | |
86 | comps='uncompressed xz gzip bzip2' | |
87 | ;; | |
88 | esac | |
89 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
90 | return 0 | |
91 | fi | |
e56056e9 | 92 | |
843cfcb1 ZJS |
93 | if [[ "$cur" = -* ]]; then |
94 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
95 | return 0 | |
96 | fi | |
e56056e9 | 97 | |
843cfcb1 ZJS |
98 | if [[ -z $verb ]]; then |
99 | comps=${VERBS[*]} | |
e56056e9 | 100 | |
843cfcb1 ZJS |
101 | elif __contains_word "$verb" ${VERBS[STANDALONE]}; then |
102 | comps='' | |
6d92077e | 103 | |
843cfcb1 ZJS |
104 | elif __contains_word "$verb" ${VERBS[MACHINES]}; then |
105 | comps=$( __get_machines ) | |
e56056e9 | 106 | |
843cfcb1 ZJS |
107 | elif __contains_word "$verb" ${VERBS[FILE]}; then |
108 | comps=$(compgen -f -- "cur") | |
109 | compopt -o filenames | |
110 | fi | |
111 | ||
112 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
113 | return 0 | |
e56056e9 TA |
114 | } |
115 | ||
116 | complete -F _machinectl machinectl |