]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shell-completion/zsh: silence error when machinectl is not installed
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Oct 2022 05:48:02 +0000 (07:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Oct 2022 07:58:00 +0000 (09:58 +0200)
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.

13 files changed:
shell-completion/bash/busctl
shell-completion/bash/journalctl
shell-completion/bash/loginctl
shell-completion/bash/machinectl
shell-completion/bash/portablectl
shell-completion/bash/systemctl.in
shell-completion/bash/systemd-analyze
shell-completion/bash/systemd-cgls
shell-completion/bash/systemd-cgtop
shell-completion/bash/systemd-nspawn
shell-completion/bash/systemd-run
shell-completion/bash/timedatectl
shell-completion/zsh/_sd_machines

index ee51c84c0b061ec6d655bd6b0e215b3691a0324e..cebd25a87180e89f7235979625974db27cbc7612 100644 (file)
@@ -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() {
index a1cfdb035c5150c7d0d4afe1f1465c8878e4e915..067b05396dada6fc4eb8b49970ecbc57a3a1ed72 100644 (file)
@@ -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)
index 7af848fdd17a3d153e2090493f581268e9724f4d..b307e428bebb4142f2d74db96fdcf48c5b49a077 100644 (file)
@@ -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 () {
index ebac999897648d40e9bd791e7ba768485deff107..b28769b0b64d9ea287e23e596132a9d6fc4adf20 100644 (file)
@@ -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() {
index 2baafb74860a11838c2b7dcfe1d97b4c7efd8e5b..71789277b09f8fced1e59c7d930be4eba5269d80 100644 (file)
@@ -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() {
index a3e423b845da213e4d4d00eebee5eb7334653f19..f935960c77e0bcb52c063ca5afddeaeaebf75cfe 100644 (file)
@@ -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 () {
index fe2c1d122c1ca0ca30da9e6d4a0c9d4b04d2e3ce..b1baec997803c2a3bc5471cfbc879c0b2188c334 100644 (file)
@@ -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() {
index 19307f9ed1b4512215bc1a7e79914a9a2b88f6b5..8dda5a82dd134fc9780b51f85cbc75b39535f8b9 100644 (file)
@@ -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() {
index ca0a51e94901adbf7d525dbc8227b1b93fb45f7b..731d9c924b178f526fba1224924377534d866f7e 100644 (file)
@@ -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() {
index fbc953f56ed2861880e87f14d55612d21942763b..cc3d2f6598ae7af90e73338362fed15e129cb0bb 100644 (file)
@@ -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() {
index 24853b28b4e35c4555c38432a59c18730260ecce..c18228d00f059f5f9a8935bc0360f171d500d885 100644 (file)
@@ -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() {
index 962fd6e37d543564480d857aab9d34974956148e..768b4a5e8206009946c26bb3aca1c552bd011122 100644 (file)
@@ -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(){
index cc0d1e2b4efcca26b5074e919cc0a577e03d753e..b960745f0d401f1519b645b063f4f15ef1145864 100644 (file)
@@ -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