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 --no-legend --no-pager 2>/dev/null |
29 { while read a b; do echo " $a"; done; };
35 busctl $mode list --no-legend --no-pager 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
89 [ARG]='--address -H --host -M --machine --match --timeout --size'
92 if __contains_word "--user" ${COMP_WORDS[*]}; then
98 if __contains_word "$prev" ${OPTS[ARG]}; then
101 comps=$(compgen -A hostname)
104 comps=$( __get_machines )
106 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
110 if [[ "$cur" = -* ]]; then
111 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
116 [STANDALONE]='list help'
117 [BUSNAME]='status monitor capture tree'
118 [OBJECT]='introspect'
120 [PROPERTY_GET]='get-property'
121 [PROPERTY_SET]='set-property'
124 for ((i=0; i < COMP_CWORD; i++)); do
125 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
126 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
127 verb=${COMP_WORDS[i]}
132 n=$(($COMP_CWORD - $i))
134 if [[ -z $verb ]]; then
136 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
138 elif __contains_word "$verb" ${VERBS[BUSNAME]}; then
139 comps=$( __get_busnames $mode)
140 elif __contains_word "$verb" ${VERBS[OBJECT]}; then
141 if [[ $n -eq 1 ]] ; then
142 comps=$( __get_busnames $mode)
143 elif [[ $n -eq 2 ]] ; then
144 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
145 elif [[ $n -eq 3 ]] ; then
146 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
150 elif __contains_word "$verb" ${VERBS[METHOD]}; then
151 if [[ $n -eq 1 ]] ; then
152 comps=$( __get_busnames $mode)
153 elif [[ $n -eq 2 ]] ; then
154 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
155 elif [[ $n -eq 3 ]] ; then
156 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
157 elif [[ $n -eq 4 ]] ; then
158 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} method)
159 elif [[ $n -eq 5 ]] ; then
160 comps=$( __get_signature $mode ${COMP_WORDS[COMP_CWORD-4]} ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
164 elif __contains_word "$verb" ${VERBS[PROPERTY_GET]}; then
165 if [[ $n -eq 1 ]] ; then
166 comps=$( __get_busnames $mode)
167 elif [[ $n -eq 2 ]] ; then
168 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
169 elif [[ $n -eq 3 ]] ; then
170 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
171 elif [[ $n -eq 4 ]] ; then
172 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} property)
176 elif __contains_word "$verb" ${VERBS[PROPERTY_SET]}; then
177 if [[ $n -eq 1 ]] ; then
178 comps=$( __get_busnames $mode)
179 elif [[ $n -eq 2 ]] ; then
180 comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
181 elif [[ $n -eq 3 ]] ; then
182 comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
183 elif [[ $n -eq 4 ]] ; then
184 comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} property writable)
185 elif [[ $n -eq 5 ]] ; then
186 comps=$( __get_signature $mode ${COMP_WORDS[COMP_CWORD-4]} ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
192 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
196 complete -F _busctl busctl