Commit Graph
1 Commits
Author SHA1 Message Date
Parag Gupta 3bc5914676 shell-completion: zsh: complete options for systemctl show
zsh only ever offered unit names after `systemctl show`, since
_systemctl_show() was sharing the same completion function as
is-active/status/preset/etc., none of which recognize `-`-prefixed
words at all. This meant `systemctl show --<TAB>` and
`systemctl show --property <TAB>` produced no completions, even
though the same options complete fine before the subcommand word
(bash has always completed both cases correctly).

Give `show` its own completion function that first tries the
existing global option specs (now pulled out into a `_sys_arguments`
array so they can be reused) via _arguments, falling back to unit
name completion for everything else. The unit-name fallback is
factored into a shared _systemctl_non_template_units() helper so it
isn't duplicated between _systemctl_show() and the existing
NONTEMPLATE_UNITS loop.

While doing so, fix pre-existing bugs in that option list which this
change makes newly reachable (and, for the filters below, newly
relevant) after `show`:

- `-P` was documented as a bare `--privileged[Acquire privileges
  before execution]` flag, which systemctl does not have. `-P NAME`
  is actually short-only and equivalent to `--value --property=NAME`
  (src/systemctl/systemctl.c); it now completes property names the
  same way `-p`/`--property` do, and is grouped next to them instead
  of sitting in `--privileged`'s old, unrelated slot.
- `-p`/`--property`, `-t`/`--type`, and `--state` all lacked the `*`
  repeatability prefix, so completion stopped offering each after its
  first use even though systemctl accumulates all three
  (parse_property_argument()/parse_types_argument()/
  parse_states_argument(), all via strv_consume()). `_loginctl`
  already uses the correct `'*'{-p+,--property=}...` form for -p.
  -t/--type and --state are both documented as filters that apply to
  `show` specifically (man/systemctl.xml), same as -p/--property.
- `--value`, documented specifically for `show` ("When showing
  properties, only print the value"), was missing from the zsh
  completion entirely, though bash already completes it.
- `-M`/`--machine=` (OPTION_COMMON_MACHINE) was likewise missing,
  despite directly affecting `show`'s bus transport the same way the
  already-present `-H`/`--host` does; `_loginctl`/`_busctl` already
  have the matching `_sd_machines`-backed spec.

Also switch both `_arguments` call sites to splice `_sys_arguments`
as `"$_sys_arguments[@]"` rather than bare, matching the prevailing
quoted-array idiom used by five other completions in this directory
(_systemd-hwdb, _userdbctl, _systemd-id128, _updatectl,
_systemd-sysupdate) and avoiding the unquoted form's behavior of
silently eliding any element that becomes empty.

Fixes #37463
2026-08-25 10:22:01 +01:00