| 1 |
# shellcheck shell=bash |
| 2 |
# systemd-dissect(1) 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_dissect() { |
| 28 |
local comps |
| 29 |
local cur=${COMP_WORDS[COMP_CWORD]} prev_1=${COMP_WORDS[COMP_CWORD-1]} prev_2=${COMP_WORDS[COMP_CWORD-2]} words cword |
| 30 |
local -A OPTS=( |
| 31 |
[STANDALONE]='-h --help --version |
| 32 |
--user |
| 33 |
--system |
| 34 |
--discover |
| 35 |
--no-pager |
| 36 |
--no-legend |
| 37 |
-r --read-only |
| 38 |
--mkdir |
| 39 |
--rmdir |
| 40 |
--in-memory' |
| 41 |
[ARG]='-m --mount -M |
| 42 |
-u --umount -U |
| 43 |
--attach |
| 44 |
--detach |
| 45 |
-l --list |
| 46 |
--mtree |
| 47 |
--with |
| 48 |
-x --copy-from |
| 49 |
-a --copy-to |
| 50 |
--validate |
| 51 |
--fsck |
| 52 |
--growfs |
| 53 |
--discard |
| 54 |
--root-hash |
| 55 |
--root-hash-sig |
| 56 |
--verity-data |
| 57 |
--image-policy |
| 58 |
--json |
| 59 |
--loop-ref |
| 60 |
--mtree-hash' |
| 61 |
) |
| 62 |
|
| 63 |
_init_completion || return |
| 64 |
|
| 65 |
if __contains_word "$prev_1" ${OPTS[STANDALONE]}; then |
| 66 |
case $prev_1 in |
| 67 |
-h|--help|--version|--discover) |
| 68 |
return 0 |
| 69 |
;; |
| 70 |
esac |
| 71 |
fi |
| 72 |
|
| 73 |
if [[ "$cur" = -* ]]; then |
| 74 |
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) |
| 75 |
return 0 |
| 76 |
fi |
| 77 |
|
| 78 |
if __contains_word "$prev_1" ${OPTS[ARG]}; then |
| 79 |
case $prev_1 in |
| 80 |
-l|--list|--mtree|-m|--mount|-M|--attach|--detach|-x|--copy-from|-a|--copy-to|--verity-data|--validate|--with) |
| 81 |
comps=$(compgen -A file -- "$cur") |
| 82 |
compopt -o filenames |
| 83 |
;; |
| 84 |
-u|--umount|-U) |
| 85 |
comps=$(compgen -A directory -- "$cur") |
| 86 |
compopt -o dirnames |
| 87 |
;; |
| 88 |
--fsck|--growfs|--mtree-hash) |
| 89 |
comps='yes no' |
| 90 |
;; |
| 91 |
--discard) |
| 92 |
comps='disabled loop all crypto' |
| 93 |
;; |
| 94 |
--root-hash-sig) |
| 95 |
comps="base64: $(compgen -A file -- "$cur")" |
| 96 |
compopt -o filenames |
| 97 |
;; |
| 98 |
--json) |
| 99 |
comps='pretty short off' |
| 100 |
;; |
| 101 |
esac |
| 102 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 103 |
return 0 |
| 104 |
fi |
| 105 |
|
| 106 |
if __contains_word "$prev_2" ${OPTS[ARG]}; then |
| 107 |
case $prev_2 in |
| 108 |
-m|--mount|-M) |
| 109 |
comps=$(compgen -A directory -- "$cur") |
| 110 |
compopt -o dirnames |
| 111 |
;; |
| 112 |
--with) |
| 113 |
comps=$(compgen -A command -- "$cur") |
| 114 |
compopt -o filenames |
| 115 |
;; |
| 116 |
*) |
| 117 |
comps=$(compgen -A file -- "$cur") |
| 118 |
compopt -o filenames |
| 119 |
;; |
| 120 |
esac |
| 121 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 122 |
return 0 |
| 123 |
fi |
| 124 |
|
| 125 |
COMPREPLY=( $(compgen -A file -- "$cur") ) |
| 126 |
compopt -o filenames |
| 127 |
return 0 |
| 128 |
} |
| 129 |
|
| 130 |
complete -F _systemd_dissect systemd-dissect |