]>
Commit | Line | Data |
---|---|---|
f8457290 | 1 | # shellcheck shell=bash |
bbcc658e | 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 | |
8546a4af | 34 | --no-reload |
bbcc658e | 35 | --force' |
36 | [ARG]='--root | |
8546a4af AZ |
37 | --json |
38 | --noexec | |
39 | --image-policy' | |
bbcc658e | 40 | ) |
41 | ||
42 | local -A VERBS=( | |
43 | [STANDALONE]='status | |
44 | merge | |
45 | unmerge | |
46 | refresh | |
47 | list' | |
48 | ) | |
49 | ||
50 | _init_completion || return | |
51 | ||
52 | if __contains_word "$prev" ${OPTS[ARG]}; then | |
53 | case $prev in | |
54 | --root) | |
55 | comps=$(compgen -A directory -- "$cur" ) | |
56 | compopt -o dirnames | |
57 | ;; | |
58 | --json) | |
59 | comps='pretty short off' | |
60 | ;; | |
8546a4af AZ |
61 | --noexec) |
62 | comps='false true' | |
63 | ;; | |
64 | --image-policy) | |
65 | comps='' | |
66 | ;; | |
bbcc658e | 67 | esac |
68 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
69 | return 0 | |
70 | fi | |
71 | ||
72 | if [[ "$cur" = -* ]]; then | |
73 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
74 | return 0 | |
75 | fi | |
76 | ||
77 | for ((i=0; i < COMP_CWORD; i++)); do | |
78 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && | |
79 | ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then | |
80 | verb=${COMP_WORDS[i]} | |
81 | break | |
82 | fi | |
83 | done | |
84 | ||
85 | if [[ -z ${verb-} ]]; then | |
86 | comps=${VERBS[*]} | |
87 | elif __contains_word "$verb" ${VERBS[STANDALONE]}; then | |
88 | comps='' | |
89 | fi | |
90 | ||
91 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
92 | return 0 | |
93 | } | |
94 | ||
95 | complete -F _systemd-confext systemd-confext |