]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shell-completion: complete --match argument for busctl 13298/head
authorRonan Pigott <rpigott@berkeley.edu>
Wed, 14 Aug 2019 03:27:56 +0000 (20:27 -0700)
committerRonan Pigott <rpigott@berkeley.edu>
Wed, 14 Aug 2019 03:27:56 +0000 (20:27 -0700)
shell-completion/zsh/_busctl

index 9c3654316eabcba0fffcfaa07c104c7bb9766ca7..0589e993265ac58f886305c038d41c87a7b9307c 100644 (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]' \