1 # resolvectl(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # 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 <http://www.gnu.org/licenses/>.
21 local w word=$1; shift
23 [[ $w = "$word" ]] && return
28 { cd /sys/class/net && echo *; } | \
29 while read -d' ' -r name; 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 --no-pager -4 -6
39 --service-address=no --service-txt=no
40 --cname=no --search=no --legend=no'
41 [ARG]='-i --interface -p --protocol -t --type -c --class --raw'
44 [DOMAIN]='query service openpgp'
47 [LINK]='revert dns domain nta'
48 [RESOLVE]='llmnr mdns'
50 [DNSOVERTLS]='dnsovertls'
51 [STANDALONE]='statistics reset-statistics flush-caches reset-server-features'
54 [FAMILY]='tcp udp sctp'
55 [RESOLVE]='yes no resolve'
56 [DNSSEC]='yes no allow-downgrade'
57 [DNSOVERTLS]='no opportunistic'
59 local interfaces=$( __get_interfaces )
61 if __contains_word "$prev" ${OPTS[ARG]}; then
66 --protocol|-p|--type|-t|--class|-c)
67 comps=$( resolvectl --legend=no "$prev" help; echo help )
70 comps="payload packet"
73 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
77 if [[ "$cur" = -* ]]; then
78 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
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
90 if [[ -z $verb ]]; then
93 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[DOMAIN]}; then
96 elif __contains_word "$verb" ${VERBS[STATUS]}; then
99 elif __contains_word "$verb" ${VERBS[FAMILY]}; then
100 for ((i++; i < COMP_CWORD; i++)); do
101 if __contains_word "${COMP_WORDS[i]}" ${ARGS[FAMILY]} &&
102 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
103 name=${COMP_WORDS[i]}
107 if [[ -z $name ]]; then
108 comps=${ARGS[FAMILY]}
113 elif __contains_word "$verb" ${VERBS[LINK]} ${VERBS[RESOLVE]} ${VERBS[DNSSEC]} ${VERBS[DNSOVERTLS]}; then
114 for ((i++; i < COMP_CWORD; i++)); do
115 if __contains_word "${COMP_WORDS[i]}" $interfaces &&
116 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
117 name=${COMP_WORDS[i]}
122 if [[ -z $name ]]; then
125 elif __contains_word "$verb" ${VERBS[RESOLVE]}; then
127 for ((i++; i < COMP_CWORD; i++)); do
128 if __contains_word "${COMP_WORDS[i]}" ${ARGS[RESOLVE]} &&
129 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
130 name=${COMP_WORDS[i]}
135 if [[ -z $name ]]; then
136 comps=${ARGS[RESOLVE]}
141 elif __contains_word "$verb" ${VERBS[DNSSEC]}; then
143 for ((i++; i < COMP_CWORD; i++)); do
144 if __contains_word "${COMP_WORDS[i]}" ${ARGS[DNSSEC]} &&
145 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
146 name=${COMP_WORDS[i]}
151 if [[ -z $name ]]; then
152 comps=${ARGS[DNSSEC]}
157 elif __contains_word "$verb" ${VERBS[DNSOVERTLS]}; then
159 for ((i++; i < COMP_CWORD; i++)); do
160 if __contains_word "${COMP_WORDS[i]}" ${ARGS[DNSOVERTLS]} &&
161 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
162 name=${COMP_WORDS[i]}
167 if [[ -z $name ]]; then
168 comps=${ARGS[DNSOVERTLS]}
178 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
182 complete -F _resolvectl resolvectl