1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
#compdef busctl -*- shell-script -*-
# SPDX-License-Identifier: LGPL-2.1+
# busctl(1) completion -*- shell-script -*-
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# systemd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
(( $+functions[_busctl_commands] )) || _busctl_commands()
{
local -a _busctl_cmds
_busctl_cmds=(
"list:List bus names"
"status:Show bus service, process or bus owner credentials"
"monitor:Show bus traffic"
"capture:Capture bus traffix as pcap"
"tree:Show object tree of service"
"introspect:Introspect object"
"call:Call a method"
"get-property:Get property value"
"set-property:Set property value"
)
if (( CURRENT == 1 )); then
_describe -t commands 'busctl command' _busctl_cmds || compadd "$@"
else
local curcontext="$curcontext"
cmd="${${_busctl_cmds[(r)$words[1]:*]%%:*}}"
curcontext="${curcontext%:*:*}:busctl-${cmd}:"
if (( $+functions[_busctl_$cmd] )); then
_busctl_$cmd
else
_message "no more options"
fi
fi
}
__busctl() {
busctl $_bus_address --no-pager --no-legend "$@" 2>/dev/null
}
(( $+functions[_busctl_get_json] )) || _busctl_get_json()
{
local -a _json_forms
_json_forms=( $(__busctl --json=help; echo help) )
_values 'format' $_json_forms
}
(( $+functions[_busctl_get_service_names] )) || _busctl_get_service_names()
{
local -a bus_names
bus_names=( $(__busctl call \
"org.freedesktop.DBus" \
"/org/freedesktop/DBus" \
"org.freedesktop.DBus" \
ListNames) )
echo ${(Q)bus_names[3,-1]}
}
(( $+functions[_busctl_get_objects] )) || _busctl_get_objects()
{
local -a objects
local name="$1"
objects=($(__busctl --list tree $name ))
echo $objects
}
(( $+functions[_busctl_get_interfaces] )) || _busctl_get_interfaces()
{
local NAME TYPE OTHER
__busctl introspect "$1" "$2" |
while read NAME TYPE OTHER; do
if [[ ${TYPE} == "interface" ]]; then
echo ${NAME}
fi
done
}
(( $+functions[_busctl_get_members] )) || _busctl_get_members()
{
local member="$4"
local required="$5"
local NAME TYPE SIGNATURE VALUE FLAGS
__busctl introspect "$1" "$2" "$3" |
while read NAME TYPE SIGNATURE VALUE FLAGS; do
[[ -z "$member" || ${TYPE} == "$member" ]] &&
[[ -z "$required" || ${${(s: :)FLAGS}[-1]} == "$required" ]] &&
echo ${NAME#.}
done
}
(( $+functions[_busctl_get_signature] )) || _busctl_get_signature()
{
local NAME TYPE SIGNATURE VALUE FLAGS
__busctl introspect "$1" "$2" "$3" |
while read NAME TYPE SIGNATURE VALUE FLAGS; do
if [[ ${NAME#.} == "$4" ]]; then
[[ ${SIGNATURE} != "-" ]] && echo ${SIGNATURE}
fi
done
}
(( $+functions[_busctl_status] )) || _busctl_status()
{
local expl
_wanted busname expl 'busname' compadd "$@" - $(_busctl_get_service_names)
}
(( $+functions[_busctl_monitor] )) || _busctl_monitor()
{
local expl
_wanted busname expl 'busname' compadd "$@" - $(_busctl_get_service_names)
}
(( $+functions[_busctl_tree] )) || _busctl_tree()
{
local expl
_wanted busname expl 'busname' compadd "$@" - $(_busctl_get_service_names)
}
(( $+functions[_busctl_introspect] )) || _busctl_introspect()
{
local expl
case $CURRENT in
2)
_wanted busname expl 'busname' \
compadd "$@" - $(_busctl_get_service_names)
;;
3)
_wanted path expl 'path' \
compadd "$@" - $(_busctl_get_objects $words[2])
;;
4)
_wanted interface expl 'interface' \
compadd "$@" - $(_busctl_get_interfaces $words[2,3])
;;
*)
_message "no more options"
esac
}
(( $+functions[_busctl_call] )) || _busctl_call()
{
local expl
case $CURRENT in
2)
_wanted busname expl 'busname' \
compadd "$@" - $(_busctl_get_service_names)
;;
3)
_wanted path expl 'path' \
compadd "$@" - $(_busctl_get_objects $words[2])
;;
4)
_wanted interface expl 'interface' \
compadd "$@" - $(_busctl_get_interfaces $words[2,3])
;;
5)
_wanted method expl 'method' \
compadd "$@" - $(_busctl_get_members $words[2,4] "method")
;;
6)
compadd "$@" - $(_busctl_get_signature $words[2,5])
;;
*)
_message "no more options"
esac
}
(( $+functions[_busctl_get-property] )) || _busctl_get-property()
{
local expl
case $CURRENT in
2)
_wanted busname expl 'busname' \
compadd "$@" - $(_busctl_get_service_names)
;;
3)
_wanted path expl 'path' \
compadd "$@" - $(_busctl_get_objects $words[2])
;;
4)
_wanted interface expl 'interface' \
compadd "$@" - $(_busctl_get_interfaces $words[2,3])
;;
5)
_wanted property expl 'property' \
compadd "$@" - $(_busctl_get_members $words[2,4] "property")
;;
*)
_message "no more options"
esac
}
(( $+functions[_busctl_set-property] )) || _busctl_set-property()
{
local expl
case $CURRENT in
2)
_wanted busname expl 'busname' \
compadd "$@" - $(_busctl_get_service_names)
;;
3)
_wanted path expl 'path' \
compadd "$@" - $(_busctl_get_objects $words[2])
;;
4)
_wanted interface expl 'interface' \
compadd "$@" - $(_busctl_get_interfaces $words[2,3])
;;
5)
_wanted property expl 'property' \
compadd "$@" - $(_busctl_get_members $words[2,4] "property" "writable")
;;
6)
compadd "$@" - $(_busctl_get_signature $words[2,5])
;;
*)
_message "no more options"
esac
}
local -a _modes; _modes=("--user" "--system")
# Use the last mode (they are exclusive and the last one is used).
local _bus_address=${${words:*_modes}[(R)(${(j.|.)_modes})]}
_arguments \
{-h,--help}'[Prints a short help text and exits.]' \
'--version[Prints a short version string and exits.]' \
'--no-pager[Do not pipe output into a pager]' \
'--no-legend[Do not show the headers and footers]' \
'--system[Connect to system manager]' \
'--user[Connect to user service manager]' \
{-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
'--address=[Connect to the bus specified by address]:address' \
'--show-machine[Show machine ID column in list]' \
'--unique[Only show unique names]' \
'--acquired[Only show acquired names]' \
'--activatable[Only show activatable names]' \
'--match=[Only show matching messages]:match' \
'--list[Do not show tree, but simple object path list]' \
{-q,--quiet}'[Do not show method call reply]'\
'--verbose[Show result values in long format]' \
'--json=[Show result values in long format]:format:_busctl_get_json' \
'-j[Show pretty json in interactive sessions, short json otherwise]' \
'--expect-reply=[Expect a method call reply]:boolean:(1 0)' \
'--auto-start=[Auto-start destination service]:boolean:(1 0)' \
'--allow-interactive-authorization=[Allow interactive authorization for operation]:boolean:(1 0)' \
'--timeout=[Maximum time to wait for method call completion]:timeout (seconds)' \
'--augment-creds=[Extend credential data with data read from /proc/$PID]:boolean:(1 0)' \
'*::busctl command:_busctl_commands'
|