1 # portablectl(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of systemd.
6 # Copyright © 2018 Yu Watanabe
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 local w word=$1; shift
24 [[ $w = "$word" ]] && return
30 machinectl list --no-legend --no-pager 2>/dev/null |
31 { while read a b; do echo " $a"; done; };
36 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
38 [STANDALONE]='-q --quiet --runtime --no-reload --cat --no-pager --no-legend
39 --no-ask-password -h --help --version'
40 [ARG]='-p --profile --copy -H --host -M --machine'
45 [IMAGE]='attach detach inspect is-attached set-limit'
47 [IMAGE_WITH_BOOL]='read-only'
50 if __contains_word "$prev" ${OPTS[ARG]}; then
53 comps="default nonetwork strict trusted"
56 comps="copy symlink auto"
59 comps=$(compgen -A hostname)
62 comps=$( __get_machines )
65 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
69 if [[ "$cur" = -* ]]; then
70 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
74 for ((i=0; i < COMP_CWORD; i++)); do
75 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
76 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
82 n=$(($COMP_CWORD - $i))
84 if [[ -z $verb ]]; then
86 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
88 elif __contains_word "$verb" ${VERBS[IMAGE]}; then
89 if [[ $n == 1 ]]; then
90 comps=$( compgen -A file -- "$cur" )
95 elif __contains_word "$verb" ${VERBS[IMAGES]}; then
96 comps=$( compgen -A file -- "$cur" )
98 elif __contains_word "$verb" ${VERBS[IMAGE_WITH_BOOL]}; then
99 if [[ $n == 1 ]]; then
100 comps=$( compgen -A file -- "$cur" )
102 elif [[ $n == 2 ]]; then
109 COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
113 complete -F _portablectl portablectl