1 # busctl(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of systemd.
6 # systemd is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation; either version 2.1 of the License, or
9 # (at your option) any later version.
11 # systemd is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 local w word=$1; shift
22 [[ $w = "$word" ]] && return
28 machinectl list --full --no-legend --no-pager 2>/dev/null |
29 { while read a b; do echo " $a"; done; };
35 busctl $mode list --no-legend --no-pager --full 2>/dev/null |
36 { while read a b; do echo " $a"; done; };
43 busctl $mode tree --list --no-legend --no-pager $busname 2>/dev/null |
44 { while read a b; do echo " $a"; done; };
52 busctl $mode introspect --list --no-legend --no-pager $busname $path 2>/dev/null |
53 { while read a b c; do [[ "$b" == "interface" ]] && echo " $a"; done; };
64 busctl $mode introspect --list --no-legend --no-pager $busname $path $interface 2>/dev/null |
66 { while read a b c d e; do [[ "$b" == "$type" && ( -z $flags || "$e" == "$flags" ) ]] && echo " $a"; done; };
76 busctl $mode introspect --list --no-legend --no-pager $busname $path $interface 2>/dev/null |
77 sed -e 's/^\.//' | { while read a b c d; do [[ "$a" == "$member" && "$c" != '-' ]] && echo " \"$c\""; done; };
81 local i n verb comps mode
82 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
84 [STANDALONE]='-h --help --version --no-pager --no-legend --system --user
85 --show-machine --unique --acquired --activatable --list
86 -q --quiet --verbose --expect-reply=no --auto-start=no
87 --allow-interactive-authorization=no --augment-creds=no
88 --watch-bind=yes -j -l --full'
89 [ARG]='--address -H --host -M --machine --match --timeout --size --json
93 if __contains_word "--user" ${COMP_WORDS[*]}; then
99 if __contains_word "$prev" ${OPTS[ARG]}; then
102 comps=$(compgen -A hostname)
105 comps=$( __get_machines )
108 comps=$( busctl --json=help 2>/dev/null )
111 comps=$( __get_busnames $mode )
114 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
118 if [[ "$cur" = -* ]]; then
119 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
124 [STANDALONE]='list help'
125 [BUSNAME]='status monitor capture tree'
126 [OBJECT]='introspect'
129 [PROPERTY_GET]='get-property'
130 [PROPERTY_SET]='set-property'
133 for ((i=0; i < COMP_CWORD; i++)); do
134 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
135 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
136 verb=${COMP_WORDS[i]}
141 n=$(($COMP_CWORD - $i))
143 if [[ -z $verb ]]; then
145 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
147 elif __contains_word "$verb" ${VERBS[BUSNAME]}; then
148 comps=$( __get_busnames $mode)
149 elif __contains_word "$verb" ${VERBS[OBJECT]}; then
150 if [[ $n -eq 1 ]] ; then
151 comps=$( __get_busnames $mode)
152 elif [[ $n -eq 2 ]] ; then
153 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
154 elif [[ $n -eq 3 ]] ; then
155 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
159 elif __contains_word "$verb" ${VERBS[METHOD]}; then
160 if [[ $n -eq 1 ]] ; then
161 comps=$( __get_busnames $mode)
162 elif [[ $n -eq 2 ]] ; then
163 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
164 elif [[ $n -eq 3 ]] ; then
165 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
166 elif [[ $n -eq 4 ]] ; then
167 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} method)
168 elif [[ $n -eq 5 ]] ; then
169 comps=$( __get_signature $mode ${COMP_WORDS[COMP_CWORD-4]} ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
173 elif __contains_word "$verb" ${VERBS[EMIT]}; then
175 elif __contains_word "$verb" ${VERBS[PROPERTY_GET]}; then
176 if [[ $n -eq 1 ]] ; then
177 comps=$( __get_busnames $mode)
178 elif [[ $n -eq 2 ]] ; then
179 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
180 elif [[ $n -eq 3 ]] ; then
181 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
182 elif [[ $n -eq 4 ]] ; then
183 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} property)
187 elif __contains_word "$verb" ${VERBS[PROPERTY_SET]}; then
188 if [[ $n -eq 1 ]] ; then
189 comps=$( __get_busnames $mode)
190 elif [[ $n -eq 2 ]] ; then
191 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
192 elif [[ $n -eq 3 ]] ; then
193 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
194 elif [[ $n -eq 4 ]] ; then
195 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} property writable)
196 elif [[ $n -eq 5 ]] ; then
197 comps=$( __get_signature $mode ${COMP_WORDS[COMP_CWORD-4]} ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
203 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
207 complete -F _busctl busctl