]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
zsh: add completion for dbus bus address
authorRonan Pigott <ronan@rjp.ie>
Sun, 26 Oct 2025 04:04:03 +0000 (21:04 -0700)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 27 Oct 2025 12:41:42 +0000 (12:41 +0000)
The DBUS_SESSION_BUS_ADDRESS and DBUS_SYSTEM_BUS_ADDRESS parameters have
an interesting syntax thats useful to complete. Let's include a
completion definition for these parameters.

shell-completion/zsh/_sd_bus_address [new file with mode: 0644]
shell-completion/zsh/meson.build

diff --git a/shell-completion/zsh/_sd_bus_address b/shell-completion/zsh/_sd_bus_address
new file mode 100644 (file)
index 0000000..a3b9105
--- /dev/null
@@ -0,0 +1,50 @@
+#compdef -value-,DBUS_SESSION_BUS_ADDRESS,-default- -value-,DBUS_SYSTEM_BUS_ADDRESS,-default-
+
+local context state state_descr line
+typeset -A val_args
+
+_values -S: kind \
+       'unix[a unix domain socket]:unix properties:->unix' \
+       'tcp[a tcp socket]:tcp properties:->tcp' \
+       'unixexec[a process]:unixexec properties:->unixexec' \
+       'x-machine-unix[a container]:machine properties:->x-machine-unix'
+
+_sd_bus_get_guid() {
+       local TYPE VALUE
+       local -a busname=(org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus)
+
+       _call_program -l dbus-guid busctl call $busname GetId |
+       while read TYPE VALUE; do
+               [[ $TYPE == 's' && -n $VALUE ]] && compadd "$@" - ${(Q)VALUE};
+       done
+}
+
+local expl ret
+case $context in
+       unix)
+               _values -s, 'unix socket properties' \
+                       'guid[bus guid]:bus guid:_sd_bus_get_guid -qS,' \
+                       '(abstract)path[unix domain socket path]:path:_files -r, -g "*(=)"' \
+                       '(path)abstract[unix domain socket path in the abstract namespace]:abstract path:_files -r, -P@ -g "*(=)"' \
+                       'uid[unix uid]:uid:_numbers' \
+                       'gid[unix gid]:gid:_numbers'
+               ;;
+       tcp)
+               _values -s, 'unix socket properties' \
+                       'guid[bus guid]:bus guid:_sd_bus_get_guid -qS,' \
+                       'host[hostname]:hostname:_hosts -r,'\
+                       'port[port]:port:_numbers' \
+                       'family[address family]:address family:(ipv4 ipv6)'
+               ;;
+       unixexec)
+               _values -s, 'unixexec properties' \
+                       'guid[bus guid]:bus guid:_sd_bus_get_guid -qS,' \
+                       'path[command path]:command path:_absolute_command_paths -r,'\
+               ;;
+       x-machine-unix)
+               _values -s, 'machine properties' \
+                       'guid[bus guid]:bus guid:_sd_bus_get_guid -qS,' \
+                       '(pid)machine[machine]:machine:_call_function ret _sd_machines' \
+                       '(machine)pid[pid]:pid:_pids'
+               ;;
+esac
index e4252c7097b55e3a11b9c68c067d9c5ce2232b2c..4de28388ce8e86f4ca129d25137f35d76a1ce803 100644 (file)
@@ -24,6 +24,7 @@ items = [['_busctl',                   ''],
          ['_udevadm',                  ''],
          ['_varlinkctl',               ''],
          ['_kernel-install',           'ENABLE_KERNEL_INSTALL'],
+         ['_sd_bus_address',           ''],
          ['_sd_hosts_or_user_at_host', ''],
          ['_sd_outputmodes',           ''],
          ['_sd_unit_files',            ''],