1 # resolvectl(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of elogind.
6 # Copyright © 2018 Yu Watanabe
8 # elogind is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # elogind is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with elogind; If not, see <http://www.gnu.org/licenses/>.
22 local w word=$1; shift
24 [[ $w = "$word" ]] && return
29 { cd /sys/class/net && echo *; } | \
30 while read -d' ' -r name; do
31 [[ "$name" != "lo" ]] && echo "$name"
36 local i comps verb name
37 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
39 [STANDALONE]='-h --help --version --no-pager -4 -6
40 --service-address=no --service-txt=no
41 --cname=no --search=no --legend=no'
42 [ARG]='-i --interface -p --protocol -t --type -c --class --raw'
45 [DOMAIN]='query service openpgp'
48 [LINK]='revert dns domain nta'
49 [RESOLVE]='llmnr mdns'
51 [DNSOVERTLS]='dnsovertls'
52 [STANDALONE]='statistics reset-statistics flush-caches reset-server-features'
55 [FAMILY]='tcp udp sctp'
56 [RESOLVE]='yes no resolve'
57 [DNSSEC]='yes no allow-downgrade'
58 [DNSOVERTLS]='no opportunistic'
60 local interfaces=$( __get_interfaces )
62 if __contains_word "$prev" ${OPTS[ARG]}; then
67 --protocol|-p|--type|-t|--class|-c)
68 comps=$( resolvectl --legend=no "$prev" help; echo help )
71 comps="payload packet"
74 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
78 if [[ "$cur" = -* ]]; then
79 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
83 for ((i=0; i < COMP_CWORD; i++)); do
84 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
85 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
91 if [[ -z $verb ]]; then
94 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[DOMAIN]}; then
97 elif __contains_word "$verb" ${VERBS[STATUS]}; then
100 elif __contains_word "$verb" ${VERBS[FAMILY]}; then
101 for ((i++; i < COMP_CWORD; i++)); do
102 if __contains_word "${COMP_WORDS[i]}" ${ARGS[FAMILY]} &&
103 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
104 name=${COMP_WORDS[i]}
108 if [[ -z $name ]]; then
109 comps=${ARGS[FAMILY]}
114 elif __contains_word "$verb" ${VERBS[LINK]} ${VERBS[RESOLVE]} ${VERBS[DNSSEC]} ${VERBS[DNSOVERTLS]}; then
115 for ((i++; i < COMP_CWORD; i++)); do
116 if __contains_word "${COMP_WORDS[i]}" $interfaces &&
117 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
118 name=${COMP_WORDS[i]}
123 if [[ -z $name ]]; then
126 elif __contains_word "$verb" ${VERBS[RESOLVE]}; then
128 for ((i++; i < COMP_CWORD; i++)); do
129 if __contains_word "${COMP_WORDS[i]}" ${ARGS[RESOLVE]} &&
130 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
131 name=${COMP_WORDS[i]}
136 if [[ -z $name ]]; then
137 comps=${ARGS[RESOLVE]}
142 elif __contains_word "$verb" ${VERBS[DNSSEC]}; then
144 for ((i++; i < COMP_CWORD; i++)); do
145 if __contains_word "${COMP_WORDS[i]}" ${ARGS[DNSSEC]} &&
146 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
147 name=${COMP_WORDS[i]}
152 if [[ -z $name ]]; then
153 comps=${ARGS[DNSSEC]}
158 elif __contains_word "$verb" ${VERBS[DNSOVERTLS]}; then
160 for ((i++; i < COMP_CWORD; i++)); do
161 if __contains_word "${COMP_WORDS[i]}" ${ARGS[DNSOVERTLS]} &&
162 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
163 name=${COMP_WORDS[i]}
168 if [[ -z $name ]]; then
169 comps=${ARGS[DNSOVERTLS]}
179 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
183 complete -F _resolvectl resolvectl