1
0
mirror of https://github.com/systemd/systemd synced 2024-07-08 20:15:55 +00:00
systemd/shell-completion/zsh/_sd_machines
Zbigniew Jędrzejewski-Szmek 4e9183059a shell-completion/zsh: silence error when machinectl is not installed
This fixes a few unrelated issues:
- when ENABLE_MACHINED is false, machinectl is not installed, but _sd_machines
  is still used in a few places that want to complete -M and such.
  Also, bash completion calls machinectl in various places.
  Make missing machinectl mean "no machines" in this case, so
  that no error is generated in the callers.
- machinectl list --full would print multiple lines of output per machine,
  breaking grep, issue introduced in e2268fa437.
  Using --max-addresses=1 would fix the issue, but let's use
  --max-addresses=0 because we now can.
- the lists used in various places were slightly different for no good reason.
- don't use a subshell if not necessary.

The code for bash still uses the same combined list of images and running
machines for various commands. The zsh code uses images for start/clone, and
running machines for the rest. Maybe something to fix in the future.

Replaces #25048.
2022-10-20 09:58:00 +02:00

20 lines
505 B
Plaintext

#autoload
# SPDX-License-Identifier: LGPL-2.1-or-later
(( $+functions[__sd_machines_get_machines] )) ||
__sd_machines_get_machines () {
{ machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo "$a"; done; } | \
sort -u
}
local -a _machines
_machines=("${(fo)$(__sd_machines_get_machines)}")
typeset -U _machines
if [[ -n "$_machines" ]]; then
_describe 'machines' _machines
else
_message 'no machines'
fi