shell-completion: complete --match argument for busctl

This commit is contained in:
Ronan Pigott 2019-08-13 20:27:56 -07:00
parent 161719d50c
commit e4e4e4954c
1 changed files with 25 additions and 1 deletions

View File

@ -50,6 +50,19 @@ __busctl() {
busctl $_bus_address --no-pager --no-legend "$@" 2>/dev/null
}
__dbus_matchspec() {
# https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing
_values -s, 'rules' \
'type[Match on message type]:type:(signal method_call method_return error)' \
'eavesdrop[Include unicast messages]:bool:(true false)' \
'sender[Match messages sent by a particular sender]:sender:{compadd $(_busctl_get_service_names)}'\
'interface[Match messages sent over or to a particular interface]:interface' \
'member[Match messages which have the given method or signal name]:member' \
'path[Match messages which are sent from or to the given object]:path' \
'path_namespace[Match messages which are sent from or to the given namespace]:namespace' \
'destination[Match messaged sent to the given unique name]:unique name:{compadd $(_busctl_get_unique_names)}'
}
(( $+functions[_busctl_get_json] )) || _busctl_get_json()
{
local -a _json_forms
@ -68,6 +81,16 @@ __busctl() {
echo ${(Q)bus_names[3,-1]}
}
(( $+functions[_busctl_get_unique_names] )) || _busctl_get_unique_names()
{
local -a bus_names
local NAME OTHER
__busctl --unique list |
while read NAME OTHER; do
echo $NAME
done
}
(( $+functions[_busctl_get_objects] )) || _busctl_get_objects()
{
local -a objects
@ -234,6 +257,7 @@ __busctl() {
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})]}
local curcontext=$curcontext state line
_arguments \
{-h,--help}'[Prints a short help text and exits.]' \
'--version[Prints a short version string and exits.]' \
@ -248,7 +272,7 @@ _arguments \
'--unique[Only show unique names]' \
'--acquired[Only show acquired names]' \
'--activatable[Only show activatable names]' \
'--match=[Only show matching messages]:match' \
'--match=[Only show matching messages]:match:__dbus_matchspec' \
'--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]' \