systemd/shell-completion/zsh/_busctl

288 lines
9.5 KiB
Plaintext
Raw Normal View History

#compdef busctl
# SPDX-License-Identifier: LGPL-2.1-or-later
2013-12-06 02:33:08 +00:00
2016-02-06 22:54:18 +00:00
# busctl(1) completion -*- shell-script -*-
2013-12-06 02:33:08 +00:00
#
# 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
2022-06-28 14:07:35 +00:00
# along with systemd; If not, see <https://www.gnu.org/licenses/>.
2013-12-06 02:33:08 +00:00
(( $+functions[_busctl_commands] )) || _busctl_commands()
2013-12-06 02:33:08 +00:00
{
local -a _busctl_cmds
_busctl_cmds=(
"list:List bus names"
2015-08-15 11:58:05 +00:00
"status:Show bus service, process or bus owner credentials"
2013-12-06 02:33:08 +00:00
"monitor:Show bus traffic"
bus-dump: change capture output to use pcapng (#21738) This patch changes busctl capture to generate pcapng format instead of the legacy pcap format files. It includes basic meta-data in the file and still uses microsecond time resolution. In future, more things can be added such as high resolution timestams, statistics, etc. PCAP Next Generation capture file format is what tshark uses and is in process of being standardized in IETF. It is also readable with libpcap. $ capinfos /tmp/new.pcapng File name: /tmp/new.pcapng File type: Wireshark/... - pcapng File encapsulation: D-Bus File timestamp precision: microseconds (6) Packet size limit: file hdr: (not set) Packet size limit: inferred: 4096 bytes Number of packets: 22 File size: 21kB Data size: 20kB Capture duration: 0.005694 seconds First packet time: 2021-12-11 11:57:42.788374 Last packet time: 2021-12-11 11:57:42.794068 Data byte rate: 3,671kBps Data bit rate: 29Mbps Average packet size: 950.27 bytes Average packet rate: 3,863 packets/s SHA256: b85ed8b094af60c64aa6d9db4a91404e841736d36b9e662d707db9e4096148f1 RIPEMD160: 81f9bac7ec0ec5cd1d55ede136a5c90413894e3a SHA1: 8400822ef724b934d6000f5b7604b9e6e91be011 Strict time order: True Capture oper-sys: Linux 5.14.0-0.bpo.2-amd64 Capture application: systemd 250 (250-rc2-33-gdc79ae2+) Number of interfaces in file: 1 Interface #0 info: Encapsulation = D-Bus (146 - dbus) Capture length = 4096 Time precision = microseconds (6) Time ticks per second = 1000000 Number of stat entries = 0 Number of packets = 22
2021-12-25 06:07:40 +00:00
"capture:Capture bus traffic"
2015-08-15 11:58:05 +00:00
"tree:Show object tree of service"
"introspect:Introspect object"
"call:Call a method"
"get-property:Get property value"
"set-property:Set property value"
2013-12-06 02:33:08 +00:00
)
if (( CURRENT == 1 )); then
_describe -t commands 'busctl command' _busctl_cmds || compadd "$@"
else
local curcontext="$curcontext"
cmd="${${_busctl_cmds[(r)$words[1]:*]%%:*}}"
2019-08-10 08:21:35 +00:00
curcontext="${curcontext%:*:*}:busctl-${cmd}:"
2013-12-06 02:33:08 +00:00
if (( $+functions[_busctl_$cmd] )); then
_busctl_$cmd
else
_message "no more options"
fi
fi
}
2019-08-10 08:21:35 +00:00
__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)}'
}
2019-08-10 08:21:35 +00:00
(( $+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_unique_names] )) || _busctl_get_unique_names()
{
local -a bus_names
local NAME OTHER
__busctl --unique list |
while read NAME OTHER; do
echo $NAME
done
}
2019-08-10 08:21:35 +00:00
(( $+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" || "${${(os: :)FLAGS}}" == $~required ]] &&
2019-08-10 08:21:35 +00:00
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*")
2019-08-10 08:21:35 +00:00
;;
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})]}
local curcontext=$curcontext state line
2013-12-06 02:33:08 +00:00
_arguments \
improve zsh completion (#32098) * fix error * remove options that are no longer supported * add missing options * stop completion if an option `--help` or `--version` is supplied [[[ zjs: a note for the reader: zshcompsys(1) in the section about optspecs in _arguments says: > Each of the forms above may be preceded by a list in parentheses of option names and argument num‐ > bers. If the given option is on the command line, the options and arguments indicated in parentheses > will not be offered. For example, ‘(-two -three 1)-one:...' completes the option ‘-one'; if this ap‐ > pears on the command line, the options -two and -three and the first ordinary argument will not be > completed after it. ‘(-foo):...' specifies an ordinary argument completion; -foo will not be com‐ > pleted if that argument is already present. > > Other items may appear in the list of excluded options to indicate various other items that should > not be applied when the current specification is matched: a single star (\*) for the rest arguments > (i.e. a specification of the form ‘\*:...'); a colon (:) for all normal (non-option-) arguments; and a > hyphen (-) for all options. For example, if ‘(\*)' appears before an option and the option appears on > the command line, the list of remaining arguments (those shown in the above table beginning with > ‘\*:') will not be completed. The intended effect of the change is to remove irrelevant completion matches from the completion. tl;dr: (- : ) prevents further completion ]]]
2024-04-15 08:58:48 +00:00
'(- *)'{-h,--help}'[Prints a short help text and exits.]' \
'(- *)--version[Prints a short version string and exits.]' \
2013-12-06 02:33:08 +00:00
'--no-pager[Do not pipe output into a pager]' \
'--no-legend[Do not show the headers and footers]' \
2013-12-06 02:33:08 +00:00
'--system[Connect to system manager]' \
'--user[Connect to user service manager]' \
improve zsh completion (#32098) * fix error * remove options that are no longer supported * add missing options * stop completion if an option `--help` or `--version` is supplied [[[ zjs: a note for the reader: zshcompsys(1) in the section about optspecs in _arguments says: > Each of the forms above may be preceded by a list in parentheses of option names and argument num‐ > bers. If the given option is on the command line, the options and arguments indicated in parentheses > will not be offered. For example, ‘(-two -three 1)-one:...' completes the option ‘-one'; if this ap‐ > pears on the command line, the options -two and -three and the first ordinary argument will not be > completed after it. ‘(-foo):...' specifies an ordinary argument completion; -foo will not be com‐ > pleted if that argument is already present. > > Other items may appear in the list of excluded options to indicate various other items that should > not be applied when the current specification is matched: a single star (\*) for the rest arguments > (i.e. a specification of the form ‘\*:...'); a colon (:) for all normal (non-option-) arguments; and a > hyphen (-) for all options. For example, if ‘(\*)' appears before an option and the option appears on > the command line, the list of remaining arguments (those shown in the above table beginning with > ‘\*:') will not be completed. The intended effect of the change is to remove irrelevant completion matches from the completion. tl;dr: (- : ) prevents further completion ]]]
2024-04-15 08:58:48 +00:00
'(-H --host)'{-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
'(-M --machine)'{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
2013-12-06 02:33:08 +00:00
'--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:__dbus_matchspec' \
2015-08-15 11:58:05 +00:00
'--list[Do not show tree, but simple object path list]' \
improve zsh completion (#32098) * fix error * remove options that are no longer supported * add missing options * stop completion if an option `--help` or `--version` is supplied [[[ zjs: a note for the reader: zshcompsys(1) in the section about optspecs in _arguments says: > Each of the forms above may be preceded by a list in parentheses of option names and argument num‐ > bers. If the given option is on the command line, the options and arguments indicated in parentheses > will not be offered. For example, ‘(-two -three 1)-one:...' completes the option ‘-one'; if this ap‐ > pears on the command line, the options -two and -three and the first ordinary argument will not be > completed after it. ‘(-foo):...' specifies an ordinary argument completion; -foo will not be com‐ > pleted if that argument is already present. > > Other items may appear in the list of excluded options to indicate various other items that should > not be applied when the current specification is matched: a single star (\*) for the rest arguments > (i.e. a specification of the form ‘\*:...'); a colon (:) for all normal (non-option-) arguments; and a > hyphen (-) for all options. For example, if ‘(\*)' appears before an option and the option appears on > the command line, the list of remaining arguments (those shown in the above table beginning with > ‘\*:') will not be completed. The intended effect of the change is to remove irrelevant completion matches from the completion. tl;dr: (- : ) prevents further completion ]]]
2024-04-15 08:58:48 +00:00
'(-q --quiet)'{-q,--quiet}'[Do not show method call reply]'\
2015-08-15 11:58:05 +00:00
'--verbose[Show result values in long format]' \
'--xml-interface[Dump the XML description in introspect command]' \
2019-08-10 08:21:35 +00:00
'--json=[Show result values in long format]:format:_busctl_get_json' \
'-j[Show pretty json in interactive sessions, short json otherwise]' \
2015-08-15 11:58:05 +00:00
'--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'