Debian Codegraph @

shell-completion/zsh/_busctl

raw
1 #compdef busctl
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 # busctl(1) completion -*- shell-script -*-
5 #
6 # This file is part of systemd.
7 #
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.
12 #
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.
17 #
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <https://www.gnu.org/licenses/>.
20
21 (( $+functions[_busctl_commands] )) || _busctl_commands()
22 {
23 local -a _busctl_cmds
24 _busctl_cmds=(
25 "list:List bus names"
26 "status:Show bus service, process or bus owner credentials"
27 "monitor:Show bus traffic"
28 "capture:Capture bus traffic"
29 "tree:Show object tree of service"
30 "introspect:Introspect object"
31 "call:Call a method"
32 "wait:Wait for a signal"
33 "get-property:Get property value"
34 "set-property:Set property value"
35 )
36 if (( CURRENT == 1 )); then
37 _describe -t commands 'busctl command' _busctl_cmds || compadd "$@"
38 else
39 local curcontext="$curcontext"
40 cmd="${${_busctl_cmds[(r)$words[1]:*]%%:*}}"
41 curcontext="${curcontext%:*:*}:busctl-${cmd}:"
42 if (( $+functions[_busctl_$cmd] )); then
43 _busctl_$cmd
44 else
45 _message "no more options"
46 fi
47 fi
48 }
49
50 __busctl() {
51 busctl $_bus_address --no-pager --no-legend "$@" 2>/dev/null
52 }
53
54 __dbus_matchspec() {
55 # https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing
56 _values -s, 'rules' \
57 'type[Match on message type]:type:(signal method_call method_return error)' \
58 'eavesdrop[Include unicast messages]:bool:(true false)' \
59 'sender[Match messages sent by a particular sender]:sender:{compadd $(_busctl_get_service_names)}'\
60 'interface[Match messages sent over or to a particular interface]:interface' \
61 'member[Match messages which have the given method or signal name]:member' \
62 'path[Match messages which are sent from or to the given object]:path' \
63 'path_namespace[Match messages which are sent from or to the given namespace]:namespace' \
64 'destination[Match messaged sent to the given unique name]:unique name:{compadd $(_busctl_get_unique_names)}'
65 }
66
67 (( $+functions[_busctl_get_json] )) || _busctl_get_json()
68 {
69 local -a _json_forms
70 _json_forms=( $(__busctl --json=help; echo help) )
71 _values 'format' $_json_forms
72 }
73
74 (( $+functions[_busctl_get_service_names] )) || _busctl_get_service_names()
75 {
76 local -a bus_names
77 bus_names=( $(__busctl call \
78 "org.freedesktop.DBus" \
79 "/org/freedesktop/DBus" \
80 "org.freedesktop.DBus" \
81 ListNames) )
82 echo ${(Q)bus_names[3,-1]}
83 }
84
85 (( $+functions[_busctl_get_unique_names] )) || _busctl_get_unique_names()
86 {
87 local -a bus_names
88 local NAME OTHER
89 __busctl --unique list |
90 while read -r NAME OTHER; do
91 echo $NAME
92 done
93 }
94
95 (( $+functions[_busctl_get_objects] )) || _busctl_get_objects()
96 {
97 local -a objects
98 local name="$1"
99 objects=($(__busctl --list tree $name ))
100 echo $objects
101 }
102
103 (( $+functions[_busctl_get_interfaces] )) || _busctl_get_interfaces()
104 {
105 local NAME TYPE OTHER
106 __busctl introspect "$1" "$2" |
107 while read -r NAME TYPE OTHER; do
108 if [[ ${TYPE} == "interface" ]]; then
109 echo ${NAME}
110 fi
111 done
112 }
113
114 (( $+functions[_busctl_get_members] )) || _busctl_get_members()
115 {
116 local member="$4"
117 local required="$5"
118 local NAME TYPE SIGNATURE VALUE FLAGS
119 __busctl introspect "$1" "$2" "$3" |
120 while read -r NAME TYPE SIGNATURE VALUE FLAGS; do
121 [[ -z "$member" || ${TYPE} == "$member" ]] &&
122 [[ -z "$required" || "${${(os: :)FLAGS}}" == $~required ]] &&
123 echo ${NAME#.}
124 done
125 }
126
127 (( $+functions[_busctl_get_signature] )) || _busctl_get_signature()
128 {
129 local NAME TYPE SIGNATURE VALUE FLAGS
130 __busctl introspect "$1" "$2" "$3" |
131 while read -r NAME TYPE SIGNATURE VALUE FLAGS; do
132 if [[ ${NAME#.} == "$4" ]]; then
133 [[ ${SIGNATURE} != "-" ]] && echo ${SIGNATURE}
134 fi
135 done
136 }
137
138 (( $+functions[_busctl_status] )) || _busctl_status()
139 {
140 local expl
141 _wanted busname expl 'busname' compadd "$@" - $(_busctl_get_service_names)
142 }
143
144 (( $+functions[_busctl_monitor] )) || _busctl_monitor()
145 {
146 local expl
147 _wanted busname expl 'busname' compadd "$@" - $(_busctl_get_service_names)
148 }
149
150 (( $+functions[_busctl_tree] )) || _busctl_tree()
151 {
152 local expl
153 _wanted busname expl 'busname' compadd "$@" - $(_busctl_get_service_names)
154 }
155
156 (( $+functions[_busctl_introspect] )) || _busctl_introspect()
157 {
158 local expl
159 case $CURRENT in
160 2)
161 _wanted busname expl 'busname' \
162 compadd "$@" - $(_busctl_get_service_names)
163 ;;
164 3)
165 _wanted path expl 'path' \
166 compadd "$@" - $(_busctl_get_objects $words[2])
167 ;;
168 4)
169 _wanted interface expl 'interface' \
170 compadd "$@" - $(_busctl_get_interfaces $words[2,3])
171 ;;
172 *)
173 _message "no more options"
174 esac
175 }
176
177 (( $+functions[_busctl_call] )) || _busctl_call()
178 {
179 local expl
180 case $CURRENT in
181 2)
182 _wanted busname expl 'busname' \
183 compadd "$@" - $(_busctl_get_service_names)
184 ;;
185 3)
186 _wanted path expl 'path' \
187 compadd "$@" - $(_busctl_get_objects $words[2])
188 ;;
189 4)
190 _wanted interface expl 'interface' \
191 compadd "$@" - $(_busctl_get_interfaces $words[2,3])
192 ;;
193 5)
194 _wanted method expl 'method' \
195 compadd "$@" - $(_busctl_get_members $words[2,4] "method")
196 ;;
197 6)
198 compadd "$@" - $(_busctl_get_signature $words[2,5])
199 ;;
200 *)
201 _message "no more options"
202 esac
203 }
204
205 (( $+functions[_busctl_wait] )) || _busctl_wait()
206 {
207 local expl
208 case $CURRENT in
209 2)
210 _wanted busname expl 'busname' \
211 compadd "$@" - $(_busctl_get_service_names)
212 ;;
213 3)
214 _wanted path expl 'path' \
215 compadd "$@" - $(_busctl_get_objects $words[2])
216 ;;
217 4)
218 _wanted interface expl 'interface' \
219 compadd "$@" - $(_busctl_get_interfaces $words[2,3])
220 ;;
221 5)
222 _wanted method expl 'method' \
223 compadd "$@" - $(_busctl_get_members $words[2,4] "signal")
224 ;;
225 *)
226 _message "no more options"
227 esac
228 }
229
230 (( $+functions[_busctl_get-property] )) || _busctl_get-property()
231 {
232 local expl
233 case $CURRENT in
234 2)
235 _wanted busname expl 'busname' \
236 compadd "$@" - $(_busctl_get_service_names)
237 ;;
238 3)
239 _wanted path expl 'path' \
240 compadd "$@" - $(_busctl_get_objects $words[2])
241 ;;
242 4)
243 _wanted interface expl 'interface' \
244 compadd "$@" - $(_busctl_get_interfaces $words[2,3])
245 ;;
246 5)
247 _wanted property expl 'property' \
248 compadd "$@" - $(_busctl_get_members $words[2,4] "property")
249 ;;
250 *)
251 _message "no more options"
252 esac
253 }
254
255 (( $+functions[_busctl_set-property] )) || _busctl_set-property()
256 {
257 local expl
258 case $CURRENT in
259 2)
260 _wanted busname expl 'busname' \
261 compadd "$@" - $(_busctl_get_service_names)
262 ;;
263 3)
264 _wanted path expl 'path' \
265 compadd "$@" - $(_busctl_get_objects $words[2])
266 ;;
267 4)
268 _wanted interface expl 'interface' \
269 compadd "$@" - $(_busctl_get_interfaces $words[2,3])
270 ;;
271 5)
272 _wanted property expl 'property' \
273 compadd "$@" - $(_busctl_get_members $words[2,4] "property" "*writable*")
274 ;;
275 6)
276 compadd "$@" - $(_busctl_get_signature $words[2,5])
277 ;;
278 *)
279 _message "no more options"
280 esac
281 }
282
283 local -a _modes; _modes=("--user" "--system")
284 # Use the last mode (they are exclusive and the last one is used).
285 local _bus_address=${${words:*_modes}[(R)(${(j.|.)_modes})]}
286 local curcontext=$curcontext state line
287 _arguments \
288 '(- *)'{-h,--help}'[Prints a short help text and exits.]' \
289 '(- *)--version[Prints a short version string and exits.]' \
290 '--no-pager[Do not pipe output into a pager]' \
291 '--no-legend[Do not show the headers and footers]' \
292 '--system[Connect to system manager]' \
293 '--user[Connect to user service manager]' \
294 '(-H --host)'{-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
295 '(-M --machine)'{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
296 '--address=[Connect to the bus specified by address]:address' \
297 '--show-machine[Show machine ID column in list]' \
298 '--unique[Only show unique names]' \
299 '--acquired[Only show acquired names]' \
300 '--activatable[Only show activatable names]' \
301 '--match=[Only show matching messages]:match:__dbus_matchspec' \
302 '--list[Do not show tree, but simple object path list]' \
303 '(-q --quiet)'{-q,--quiet}'[Do not show method call reply]'\
304 '--verbose[Show result values in long format]' \
305 '--xml-interface[Dump the XML description in introspect command]' \
306 '--json=[Show result values in long format]:format:_busctl_get_json' \
307 '-j[Show pretty json in interactive sessions, short json otherwise]' \
308 '--expect-reply=[Expect a method call reply]:boolean:(1 0)' \
309 '--auto-start=[Auto-start destination service]:boolean:(1 0)' \
310 '--allow-interactive-authorization=[Allow interactive authorization for operation]:boolean:(1 0)' \
311 '--timeout=[Maximum time to wait for method call completion and monitoring]:timeout (seconds)' \
312 '--augment-creds=[Extend credential data with data read from /proc/$PID]:boolean:(1 0)' \
313 '(-M --limit-messages)'{-M,--limit-messages}'[Exit after receiving a number of messages while monitoring]:integer' \
314 '*::busctl command:_busctl_commands'