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