Debian Codegraph @

shell-completion/bash/systemd-confext

raw
1 # shellcheck shell=bash
2 # systemd-confext(8) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
4 #
5 # This file is part of systemd.
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 <https://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 _systemd-confext() {
28 local i verb comps
29 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
30 local -A OPTS=(
31 [STANDALONE]='-h --help --version
32 --no-pager
33 --no-legend
34 --no-reload
35 --force'
36 [ARG]='--root
37 --json
38 --noexec
39 --image-policy
40 --mutable'
41 )
42
43 local -A VERBS=(
44 [STANDALONE]='status
45 merge
46 unmerge
47 refresh
48 list'
49 )
50
51 _init_completion || return
52
53 if __contains_word "$prev" ${OPTS[ARG]}; then
54 case $prev in
55 --root)
56 comps=$(compgen -A directory -- "$cur" )
57 compopt -o dirnames
58 ;;
59 --json)
60 comps='pretty short off'
61 ;;
62 --noexec)
63 comps='no yes'
64 ;;
65 --image-policy)
66 comps=''
67 ;;
68 --mutable)
69 comps=$( systemd-confext --no-legend --mutable=help 2>/dev/null; echo help )
70 ;;
71 esac
72 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
73 return 0
74 fi
75
76 if [[ "$cur" = -* ]]; then
77 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
78 return 0
79 fi
80
81 for ((i=0; i < COMP_CWORD; i++)); do
82 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
83 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
84 verb=${COMP_WORDS[i]}
85 break
86 fi
87 done
88
89 if [[ -z ${verb-} ]]; then
90 comps=${VERBS[*]}
91 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
92 comps=''
93 fi
94
95 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
96 return 0
97 }
98
99 complete -F _systemd-confext systemd-confext