| 1 |
# shellcheck shell=bash |
| 2 |
# systemd-sysext(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-sysext() { |
| 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 |
--always-refresh |
| 40 |
--image-policy |
| 41 |
--mutable' |
| 42 |
) |
| 43 |
|
| 44 |
local -A VERBS=( |
| 45 |
[STANDALONE]='status |
| 46 |
merge |
| 47 |
unmerge |
| 48 |
refresh |
| 49 |
list' |
| 50 |
) |
| 51 |
|
| 52 |
_init_completion || return |
| 53 |
|
| 54 |
if __contains_word "$prev" ${OPTS[ARG]}; then |
| 55 |
case $prev in |
| 56 |
--root) |
| 57 |
comps=$(compgen -A directory -- "$cur" ) |
| 58 |
compopt -o dirnames |
| 59 |
;; |
| 60 |
--json) |
| 61 |
comps='pretty short off' |
| 62 |
;; |
| 63 |
--noexec|--always-refresh) |
| 64 |
comps='no yes' |
| 65 |
;; |
| 66 |
--image-policy) |
| 67 |
comps='' |
| 68 |
;; |
| 69 |
--mutable) |
| 70 |
comps=$( systemd-sysext --no-legend --mutable=help 2>/dev/null; echo help ) |
| 71 |
;; |
| 72 |
esac |
| 73 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 74 |
return 0 |
| 75 |
fi |
| 76 |
|
| 77 |
if [[ "$cur" = -* ]]; then |
| 78 |
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) |
| 79 |
return 0 |
| 80 |
fi |
| 81 |
|
| 82 |
for ((i=0; i < COMP_CWORD; i++)); do |
| 83 |
if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && |
| 84 |
! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then |
| 85 |
verb=${COMP_WORDS[i]} |
| 86 |
break |
| 87 |
fi |
| 88 |
done |
| 89 |
|
| 90 |
if [[ -z ${verb-} ]]; then |
| 91 |
comps=${VERBS[*]} |
| 92 |
elif __contains_word "$verb" ${VERBS[STANDALONE]}; then |
| 93 |
comps='' |
| 94 |
fi |
| 95 |
|
| 96 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 97 |
return 0 |
| 98 |
} |
| 99 |
|
| 100 |
complete -F _systemd-sysext systemd-sysext |