summaryrefslogtreecommitdiff
path: root/shell-completion
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-10-20 07:48:02 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-10-20 09:58:00 +0200
commit4e9183059a5738cd19a8bee76189889087c0610e (patch)
tree29b90ff812f87e547a8a04f8a947b2453a412244 /shell-completion
parent99b8149ae13730a0e87507a5375dabf22bc3f3b7 (diff)
downloadsystemd-4e9183059a5738cd19a8bee76189889087c0610e.tar.gz
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 e2268fa43742ece4a5cdc2e93f731b2bb2fcc883. 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.
Diffstat (limited to 'shell-completion')
-rw-r--r--shell-completion/bash/busctl5
-rw-r--r--shell-completion/bash/journalctl5
-rw-r--r--shell-completion/bash/loginctl5
-rw-r--r--shell-completion/bash/machinectl5
-rw-r--r--shell-completion/bash/portablectl5
-rw-r--r--shell-completion/bash/systemctl.in5
-rw-r--r--shell-completion/bash/systemd-analyze4
-rw-r--r--shell-completion/bash/systemd-cgls4
-rw-r--r--shell-completion/bash/systemd-cgtop4
-rw-r--r--shell-completion/bash/systemd-nspawn4
-rw-r--r--shell-completion/bash/systemd-run4
-rw-r--r--shell-completion/bash/timedatectl4
-rw-r--r--shell-completion/zsh/_sd_machines5
13 files changed, 40 insertions, 19 deletions
diff --git a/shell-completion/bash/busctl b/shell-completion/bash/busctl
index ee51c84c0b..cebd25a871 100644
--- a/shell-completion/bash/busctl
+++ b/shell-completion/bash/busctl
@@ -25,8 +25,9 @@ __contains_word () {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager 2>/dev/null |
- { while read a b; do echo " $a"; done; };
+ { 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
}
__get_busnames() {
diff --git a/shell-completion/bash/journalctl b/shell-completion/bash/journalctl
index a1cfdb035c..067b05396d 100644
--- a/shell-completion/bash/journalctl
+++ b/shell-completion/bash/journalctl
@@ -27,8 +27,9 @@ __contains_word () {
__get_machines() {
local a b
- (machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \
- { while read a b; do echo " $a"; done; } | sort -u;
+ { 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
}
__syslog_priorities=(emerg alert crit err warning notice info debug)
diff --git a/shell-completion/bash/loginctl b/shell-completion/bash/loginctl
index 7af848fdd1..b307e428be 100644
--- a/shell-completion/bash/loginctl
+++ b/shell-completion/bash/loginctl
@@ -31,8 +31,9 @@ __get_all_seats () { loginctl --no-legend list-seats | { while read -r a b
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager 2>/dev/null |
- { while read a b; do echo " $a"; done; };
+ { 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
}
_loginctl () {
diff --git a/shell-completion/bash/machinectl b/shell-completion/bash/machinectl
index ebac999897..b28769b0b6 100644
--- a/shell-completion/bash/machinectl
+++ b/shell-completion/bash/machinectl
@@ -25,8 +25,9 @@ __contains_word() {
__get_machines() {
local a b
- (machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \
- { while read a b; do echo " $a"; done; } | sort -u;
+ { machinectl list-images --full --no-legend --no-pager 2>/dev/null; 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
}
_machinectl() {
diff --git a/shell-completion/bash/portablectl b/shell-completion/bash/portablectl
index 2baafb7486..71789277b0 100644
--- a/shell-completion/bash/portablectl
+++ b/shell-completion/bash/portablectl
@@ -25,8 +25,9 @@ __contains_word () {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager 2>/dev/null |
- { while read a b; do echo " $a"; done; };
+ { 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
}
_portablectl() {
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index a3e423b845..f935960c77 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -115,8 +115,9 @@ __get_all_unit_files () { { __systemctl $1 list-unit-files "$2*"; } | { while re
__get_machines() {
local a b
- { machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; } | \
- { while read a b; do echo " $a"; done; }
+ { 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
}
_systemctl () {
diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze
index fe2c1d122c..b1baec9978 100644
--- a/shell-completion/bash/systemd-analyze
+++ b/shell-completion/bash/systemd-analyze
@@ -27,7 +27,9 @@ __contains_word () {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { 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
}
__get_units_all() {
diff --git a/shell-completion/bash/systemd-cgls b/shell-completion/bash/systemd-cgls
index 19307f9ed1..8dda5a82dd 100644
--- a/shell-completion/bash/systemd-cgls
+++ b/shell-completion/bash/systemd-cgls
@@ -25,7 +25,9 @@ __contains_word() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { 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
}
__get_units_have_cgroup() {
diff --git a/shell-completion/bash/systemd-cgtop b/shell-completion/bash/systemd-cgtop
index ca0a51e949..731d9c924b 100644
--- a/shell-completion/bash/systemd-cgtop
+++ b/shell-completion/bash/systemd-cgtop
@@ -25,7 +25,9 @@ __contains_word() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { 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
}
_systemd_cgtop() {
diff --git a/shell-completion/bash/systemd-nspawn b/shell-completion/bash/systemd-nspawn
index fbc953f56e..cc3d2f6598 100644
--- a/shell-completion/bash/systemd-nspawn
+++ b/shell-completion/bash/systemd-nspawn
@@ -35,7 +35,9 @@ __get_slices() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { 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
}
__get_env() {
diff --git a/shell-completion/bash/systemd-run b/shell-completion/bash/systemd-run
index 24853b28b4..c18228d00f 100644
--- a/shell-completion/bash/systemd-run
+++ b/shell-completion/bash/systemd-run
@@ -26,7 +26,9 @@ __get_slice_units () { __systemctl $1 list-units --all -t slice \
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { 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
}
_systemd_run() {
diff --git a/shell-completion/bash/timedatectl b/shell-completion/bash/timedatectl
index 962fd6e37d..768b4a5e82 100644
--- a/shell-completion/bash/timedatectl
+++ b/shell-completion/bash/timedatectl
@@ -27,7 +27,9 @@ __contains_word () {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { 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
}
__get_interfaces(){
diff --git a/shell-completion/zsh/_sd_machines b/shell-completion/zsh/_sd_machines
index cc0d1e2b4e..b960745f0d 100644
--- a/shell-completion/zsh/_sd_machines
+++ b/shell-completion/zsh/_sd_machines
@@ -3,7 +3,10 @@
(( $+functions[__sd_machines_get_machines] )) ||
__sd_machines_get_machines () {
- machinectl --full --no-legend --no-pager list | {while read -r a b; do echo $a; done;};
+
+ { 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