1 # resolvectl(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of systemd.
6 # Copyright 2018 Yu Watanabe
8 # systemd 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 # systemd 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 systemd; 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 [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'
58 local interfaces=$( __get_interfaces )
60 if __contains_word "$prev" ${OPTS[ARG]}; then
65 --protocol|-p|--type|-t|--class|-c)
66 comps=$( resolvectl --legend=no "$prev" help; echo help )
69 comps="payload packet"
72 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
76 if [[ "$cur" = -* ]]; then
77 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
81 for ((i=0; i < COMP_CWORD; i++)); do
82 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
83 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
89 if [[ -z $verb ]]; then
92 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[DOMAIN]}; then
95 elif __contains_word "$verb" ${VERBS[STATUS]}; then
98 elif __contains_word "$verb" ${VERBS[FAMILY]}; then
99 for ((i++; i < COMP_CWORD; i++)); do
100 if __contains_word "${COMP_WORDS[i]}" ${ARGS[FAMILY]} &&
101 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
102 name=${COMP_WORDS[i]}
106 if [[ -z $name ]]; then
107 comps=${ARGS[FAMILY]}
112 elif __contains_word "$verb" ${VERBS[LINK]} ${VERBS[RESOLVE]} ${VERBS[DNSSEC]}; then
113 for ((i++; i < COMP_CWORD; i++)); do
114 if __contains_word "${COMP_WORDS[i]}" $interfaces &&
115 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
116 name=${COMP_WORDS[i]}
121 if [[ -z $name ]]; then
124 elif __contains_word "$verb" ${VERBS[RESOLVE]}; then
126 for ((i++; i < COMP_CWORD; i++)); do
127 if __contains_word "${COMP_WORDS[i]}" ${ARGS[RESOLVE]} &&
128 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
129 name=${COMP_WORDS[i]}
134 if [[ -z $name ]]; then
135 comps=${ARGS[RESOLVE]}
140 elif __contains_word "$verb" ${VERBS[DNSSEC]}; then
142 for ((i++; i < COMP_CWORD; i++)); do
143 if __contains_word "${COMP_WORDS[i]}" ${ARGS[DNSSEC]} &&
144 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
145 name=${COMP_WORDS[i]}
150 if [[ -z $name ]]; then
151 comps=${ARGS[DNSSEC]}
161 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
165 complete -F _resolvectl resolvectl