]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/resolvectl
units: Order ldconfig after systemd-tmpfiles-setup.service
[thirdparty/systemd.git] / shell-completion / bash / resolvectl
CommitLineData
f8457290 1# shellcheck shell=bash
bd188ff0 2# resolvectl(1) completion -*- shell-script -*-
db9ecf05 3# SPDX-License-Identifier: LGPL-2.1-or-later
bd188ff0
YW
4#
5# This file is part of systemd.
6#
bd188ff0
YW
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
85fce6f4 18# along with systemd; If not, see <https://www.gnu.org/licenses/>.
bd188ff0
YW
19
20__contains_word () {
843cfcb1
ZJS
21 local w word=$1; shift
22 for w in "$@"; do
23 [[ $w = "$word" ]] && return
24 done
bd188ff0
YW
25}
26
4a06acda 27__get_interfaces() {
843cfcb1 28 local name
66e10d45 29 for name in $(cd /sys/class/net && command ls); do
843cfcb1
ZJS
30 [[ "$name" != "lo" ]] && echo "$name"
31 done
bd188ff0
YW
32}
33
34_resolvectl() {
843cfcb1
ZJS
35 local i comps verb name
36 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
37 local -A OPTS=(
4e5f4733 38 [STANDALONE]='-h --help --version -4 -6 --legend=no --cname=no
4a06acda 39 --validate=no --synthesize=no --cache=no --relax-single-label=no --zone=no
4e5f4733 40 --trust-anchor=no --network=no --service-address=no
5703301a 41 --service-txt=no --search=no --stale-data=no --no-pager --no-ask-password'
4a06acda 42 [ARG]='-t --type -c --class -i --interface -p --protocol --raw --json'
843cfcb1
ZJS
43 )
44 local -A VERBS=(
45 [DOMAIN]='query service openpgp'
46 [FAMILY]='tlsa'
47 [STATUS]='status'
48 [LINK]='revert dns domain nta'
4e5f4733 49 [BOOLEAN]='default-route'
843cfcb1
ZJS
50 [RESOLVE]='llmnr mdns'
51 [DNSSEC]='dnssec'
52 [DNSOVERTLS]='dnsovertls'
4a06acda 53 [STANDALONE]='statistics reset-statistics flush-caches reset-server-features monitor show-cache show-server-state'
3605aae1 54 [LOG_LEVEL]='log-level'
843cfcb1
ZJS
55 )
56 local -A ARGS=(
57 [FAMILY]='tcp udp sctp'
4e5f4733 58 [BOOLEAN]='yes no'
843cfcb1
ZJS
59 [RESOLVE]='yes no resolve'
60 [DNSSEC]='yes no allow-downgrade'
4310bfc2 61 [DNSOVERTLS]='yes no opportunistic'
843cfcb1 62 )
843cfcb1
ZJS
63
64 if __contains_word "$prev" ${OPTS[ARG]}; then
65 case $prev in
66 --interface|-i)
4a06acda 67 comps=$( __get_interfaces )
843cfcb1 68 ;;
4a06acda 69 --protocol|-p|--type|-t|--class|-c|--json)
843cfcb1
ZJS
70 comps=$( resolvectl --legend=no "$prev" help; echo help )
71 ;;
72 --raw)
73 comps="payload packet"
74 ;;
75 esac
76 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
77 return 0
78 fi
bd188ff0 79
843cfcb1
ZJS
80 if [[ "$cur" = -* ]]; then
81 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
82 return 0
83 fi
84
85 for ((i=0; i < COMP_CWORD; i++)); do
86 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
87 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
88 verb=${COMP_WORDS[i]}
89 break
bd188ff0 90 fi
843cfcb1 91 done
bd188ff0 92
36ec0268 93 if [[ -z ${verb-} ]]; then
843cfcb1
ZJS
94 comps="${VERBS[*]}"
95
96 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[DOMAIN]}; then
97 comps=''
98
99 elif __contains_word "$verb" ${VERBS[STATUS]}; then
4a06acda 100 comps=$( __get_interfaces )
843cfcb1 101
3605aae1
YW
102 elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
103 comps='debug info notice warning err crit alert emerg'
104
843cfcb1
ZJS
105 elif __contains_word "$verb" ${VERBS[FAMILY]}; then
106 for ((i++; i < COMP_CWORD; i++)); do
107 if __contains_word "${COMP_WORDS[i]}" ${ARGS[FAMILY]} &&
108 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
109 name=${COMP_WORDS[i]}
110 break;
111 fi
bd188ff0 112 done
843cfcb1
ZJS
113 if [[ -z $name ]]; then
114 comps=${ARGS[FAMILY]}
115 else
116 comps=""
117 fi
bd188ff0 118
4e5f4733 119 elif __contains_word "$verb" ${VERBS[LINK]} ${VERBS[BOOLEAN]} ${VERBS[RESOLVE]} ${VERBS[DNSSEC]} ${VERBS[DNSOVERTLS]}; then
4a06acda 120 local interfaces=$( __get_interfaces )
843cfcb1
ZJS
121 for ((i++; i < COMP_CWORD; i++)); do
122 if __contains_word "${COMP_WORDS[i]}" $interfaces &&
123 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
124 name=${COMP_WORDS[i]}
125 break;
126 fi
127 done
bd188ff0 128
843cfcb1
ZJS
129 if [[ -z $name ]]; then
130 comps="$interfaces"
bd188ff0 131
843cfcb1
ZJS
132 elif __contains_word "$verb" ${VERBS[RESOLVE]}; then
133 name=
134 for ((i++; i < COMP_CWORD; i++)); do
135 if __contains_word "${COMP_WORDS[i]}" ${ARGS[RESOLVE]} &&
136 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
137 name=${COMP_WORDS[i]}
138 break;
139 fi
140 done
bd188ff0 141
843cfcb1
ZJS
142 if [[ -z $name ]]; then
143 comps=${ARGS[RESOLVE]}
144 else
145 comps=''
146 fi
147
4e5f4733
YW
148 elif __contains_word "$verb" ${VERBS[BOOLEAN]}; then
149 name=
150 for ((i++; i < COMP_CWORD; i++)); do
151 if __contains_word "${COMP_WORDS[i]}" ${ARGS[BOOLEAN]} &&
152 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
153 name=${COMP_WORDS[i]}
154 break;
155 fi
156 done
157
158 if [[ -z $name ]]; then
159 comps=${ARGS[BOOLEAN]}
160 else
161 comps=''
162 fi
163
843cfcb1
ZJS
164 elif __contains_word "$verb" ${VERBS[DNSSEC]}; then
165 name=
166 for ((i++; i < COMP_CWORD; i++)); do
167 if __contains_word "${COMP_WORDS[i]}" ${ARGS[DNSSEC]} &&
168 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
169 name=${COMP_WORDS[i]}
170 break;
bd188ff0 171 fi
843cfcb1 172 done
bd188ff0 173
843cfcb1
ZJS
174 if [[ -z $name ]]; then
175 comps=${ARGS[DNSSEC]}
176 else
177 comps=''
178 fi
179
180 elif __contains_word "$verb" ${VERBS[DNSOVERTLS]}; then
181 name=
182 for ((i++; i < COMP_CWORD; i++)); do
183 if __contains_word "${COMP_WORDS[i]}" ${ARGS[DNSOVERTLS]} &&
184 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
185 name=${COMP_WORDS[i]}
186 break;
bd188ff0 187 fi
843cfcb1
ZJS
188 done
189
190 if [[ -z $name ]]; then
191 comps=${ARGS[DNSOVERTLS]}
192 else
193 comps=''
194 fi
195
196 else
197 comps=''
bd188ff0 198 fi
843cfcb1 199 fi
bd188ff0 200
843cfcb1
ZJS
201 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
202 return 0
bd188ff0
YW
203}
204
205complete -F _resolvectl resolvectl