1 # shellcheck shell=bash
2 # machinectl(1) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
5 # This file is part of systemd.
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.
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.
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <https://www.gnu.org/licenses/>.
21 local w word=$1; shift
23 [[ $w = "$word" ]] && return
29 { machinectl list-images --full --no-legend --no-pager 2>/dev/null; machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
30 { while read a b; do echo " $a"; done; } | \
35 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
39 [STANDALONE]='--all -a -l --full --help -h --no-ask-password --no-legend --no-pager --version --value
40 --mkdir --read-only --force -q --quiet'
41 [ARG]='--host -H --kill-whom -M --machine --property -p --signal -s --uid -E --setenv -n --lines
42 -o --output --verify --format --max-addresses'
46 [STANDALONE]='list list-images clean pull-tar pull-raw list-transfers cancel-transfer import-fs'
47 [MACHINES]='status show start stop login shell enable disable poweroff reboot terminate kill bind
48 copy-to copy-from image-status show-image clone rename read-only remove set-limit
49 export-tar export-raw'
50 [FILE]='import-tar import-raw'
53 _init_completion || return
55 for ((i=0; i <= COMP_CWORD; i++)); do
56 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
57 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
63 if __contains_word "$prev" ${OPTS[ARG]}; then
69 --kill-whom|--kill-who)
73 comps=$(compgen -A hostname)
76 comps=$( __get_machines )
82 comps=$( machinectl --output=help 2>/dev/null )
85 comps=$( machinectl --verify=help 2>/dev/null )
88 comps='uncompressed xz gzip bzip2 zstd'
91 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
95 if [[ "$cur" = -* ]]; then
96 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
100 if [[ -z ${verb-} ]]; then
103 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
106 elif __contains_word "$verb" ${VERBS[MACHINES]}; then
107 comps=$( __get_machines )
109 elif __contains_word "$verb" ${VERBS[FILE]}; then
110 if (( COMP_CWORD == i + 1 )); then # first argument after verb
111 comps=$(compgen -f -- "$cur")
118 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
122 complete -F _machinectl machinectl