1 # shellcheck shell=bash
2 # resolvectl(1) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
5 # This file is part of systemd.
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.
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.
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/>.
21 local w word=$1; shift
23 [[ $w = "$word" ]] && return
29 for name in $(cd /sys/class/net && command ls); do
30 [[ "$name" != "lo" ]] && echo "$name"
35 local i comps verb name
36 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
38 [STANDALONE]='-h --help --version -4 -6 --legend=no --cname=no
39 --validate=no --synthesize=no --cache=no --relax-single-label=no --zone=no
40 --trust-anchor=no --network=no --service-address=no
41 --service-txt=no --search=no --stale-data=no --no-pager'
42 [ARG]='-t --type -c --class -i --interface -p --protocol --raw --json'
45 [DOMAIN]='query service openpgp'
48 [LINK]='revert dns domain nta'
49 [BOOLEAN]='default-route'
50 [RESOLVE]='llmnr mdns'
52 [DNSOVERTLS]='dnsovertls'
53 [STANDALONE]='statistics reset-statistics flush-caches reset-server-features monitor show-cache show-server-state'
54 [LOG_LEVEL]='log-level'
57 [FAMILY]='tcp udp sctp'
59 [RESOLVE]='yes no resolve'
60 [DNSSEC]='yes no allow-downgrade'
61 [DNSOVERTLS]='yes no opportunistic'
64 if __contains_word "$prev" ${OPTS[ARG]}; then
67 comps=$( __get_interfaces )
69 --protocol|-p|--type|-t|--class|-c|--json)
70 comps=$( resolvectl --legend=no "$prev" help; echo help )
73 comps="payload packet"
76 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
80 if [[ "$cur" = -* ]]; then
81 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
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
93 if [[ -z ${verb-} ]]; then
96 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[DOMAIN]}; then
99 elif __contains_word "$verb" ${VERBS[STATUS]}; then
100 comps=$( __get_interfaces )
102 elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
103 comps='debug info notice warning err crit alert emerg'
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]}
113 if [[ -z $name ]]; then
114 comps=${ARGS[FAMILY]}
119 elif __contains_word "$verb" ${VERBS[LINK]} ${VERBS[BOOLEAN]} ${VERBS[RESOLVE]} ${VERBS[DNSSEC]} ${VERBS[DNSOVERTLS]}; then
120 local interfaces=$( __get_interfaces )
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]}
129 if [[ -z $name ]]; then
132 elif __contains_word "$verb" ${VERBS[RESOLVE]}; then
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]}
142 if [[ -z $name ]]; then
143 comps=${ARGS[RESOLVE]}
148 elif __contains_word "$verb" ${VERBS[BOOLEAN]}; then
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]}
158 if [[ -z $name ]]; then
159 comps=${ARGS[BOOLEAN]}
164 elif __contains_word "$verb" ${VERBS[DNSSEC]}; then
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]}
174 if [[ -z $name ]]; then
175 comps=${ARGS[DNSSEC]}
180 elif __contains_word "$verb" ${VERBS[DNSOVERTLS]}; then
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]}
190 if [[ -z $name ]]; then
191 comps=${ARGS[DNSOVERTLS]}
201 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
205 complete -F _resolvectl resolvectl