1 # busctl(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of systemd.
6 # Copyright 2013 Zbigniew Jędrzejewski-Szmek
7 # Copyright 2014 Thomas H.P. Andersen
9 # systemd is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or
12 # (at your option) any later version.
14 # systemd is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 local w word=$1; shift
25 [[ $w = "$word" ]] && return
31 machinectl list --no-legend --no-pager 2>/dev/null |
32 { while read a b; do echo " $a"; done; };
38 busctl $mode list --no-legend --no-pager 2>/dev/null |
39 { while read a b; do echo " $a"; done; };
46 busctl $mode tree --list --no-legend --no-pager $busname 2>/dev/null |
47 { while read a b; do echo " $a"; done; };
55 busctl $mode introspect --list --no-legend --no-pager $busname $path 2>/dev/null |
56 { while read a b c; do [[ "$b" == "interface" ]] && echo " $a"; done; };
67 busctl $mode introspect --list --no-legend --no-pager $busname $path $interface 2>/dev/null |
69 { while read a b c d e; do [[ "$b" == "$type" && ( -z $flags || "$e" == "$flags" ) ]] && echo " $a"; done; };
79 busctl $mode introspect --list --no-legend --no-pager $busname $path $interface 2>/dev/null |
80 sed -e 's/^\.//' | { while read a b c d; do [[ "$a" == "$member" && "$c" != '-' ]] && echo " \"$c\""; done; };
84 local i n verb comps mode
85 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
87 [STANDALONE]='-h --help --version --no-pager --no-legend --system --user
88 --show-machine --unique --acquired --activatable --list
89 -q --quiet --verbose --expect-reply=no --auto-start=no
90 --allow-interactive-authorization=no --augment-creds=no
92 [ARG]='--address -H --host -M --machine --match --timeout --size'
95 if __contains_word "--user" ${COMP_WORDS[*]}; then
101 if __contains_word "$prev" ${OPTS[ARG]}; then
104 comps=$(compgen -A hostname)
107 comps=$( __get_machines )
109 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
113 if [[ "$cur" = -* ]]; then
114 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
119 [STANDALONE]='list help'
120 [BUSNAME]='status monitor capture tree'
121 [OBJECT]='introspect'
123 [PROPERTY_GET]='get-property'
124 [PROPERTY_SET]='set-property'
127 for ((i=0; i < COMP_CWORD; i++)); do
128 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
129 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
130 verb=${COMP_WORDS[i]}
135 n=$(($COMP_CWORD - $i))
137 if [[ -z $verb ]]; then
139 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
141 elif __contains_word "$verb" ${VERBS[BUSNAME]}; then
142 comps=$( __get_busnames $mode)
143 elif __contains_word "$verb" ${VERBS[OBJECT]}; then
144 if [[ $n -eq 1 ]] ; then
145 comps=$( __get_busnames $mode)
146 elif [[ $n -eq 2 ]] ; then
147 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
148 elif [[ $n -eq 3 ]] ; then
149 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
153 elif __contains_word "$verb" ${VERBS[METHOD]}; then
154 if [[ $n -eq 1 ]] ; then
155 comps=$( __get_busnames $mode)
156 elif [[ $n -eq 2 ]] ; then
157 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
158 elif [[ $n -eq 3 ]] ; then
159 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
160 elif [[ $n -eq 4 ]] ; then
161 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} method)
162 elif [[ $n -eq 5 ]] ; then
163 comps=$( __get_signature $mode ${COMP_WORDS[COMP_CWORD-4]} ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
167 elif __contains_word "$verb" ${VERBS[PROPERTY_GET]}; then
168 if [[ $n -eq 1 ]] ; then
169 comps=$( __get_busnames $mode)
170 elif [[ $n -eq 2 ]] ; then
171 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
172 elif [[ $n -eq 3 ]] ; then
173 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
174 elif [[ $n -eq 4 ]] ; then
175 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} property)
179 elif __contains_word "$verb" ${VERBS[PROPERTY_SET]}; then
180 if [[ $n -eq 1 ]] ; then
181 comps=$( __get_busnames $mode)
182 elif [[ $n -eq 2 ]] ; then
183 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
184 elif [[ $n -eq 3 ]] ; then
185 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
186 elif [[ $n -eq 4 ]] ; then
187 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} property writable)
188 elif [[ $n -eq 5 ]] ; then
189 comps=$( __get_signature $mode ${COMP_WORDS[COMP_CWORD-4]} ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
195 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
199 complete -F _busctl busctl