]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
zsh-completion: optimize _filter_units_by_property 84/head
authorDaniel Hahler <git@thequod.de>
Wed, 27 May 2015 19:26:26 +0000 (21:26 +0200)
committerDaniel Hahler <git@thequod.de>
Sat, 6 Jun 2015 10:54:41 +0000 (12:54 +0200)
Optimize _filter_units_by_property by calling `systemctl` only once with
a list of units, and not once per unit.

I could not reproduce the "Unknown unit" error mentioned in a FIXME,
which might have made this necessary previously.

shell-completion/zsh/_systemctl.in

index 17736de01c66998e08e27aa40dce632d82eb55f2..4bf306aacb4cd7f1a606827e64fb8f3e00b780ed 100644 (file)
@@ -127,16 +127,11 @@ _systemctl_really_all_units()
 _filter_units_by_property() {
   local property=$1 value=$2 ; shift ; shift
   local -a units ; units=($*)
-  local prop unit
-  for ((i=1; $i <= ${#units[*]}; i++)); do
-    # FIXME: "Failed to issue method call: Unknown unit" errors are ignored for
-    # now (related to DBUS_ERROR_UNKNOWN_OBJECT). in the future, we need to
-    # revert to calling 'systemctl show' once for all units, which is way
-    # faster
-    unit=${units[i]}
-    prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"}
-    if [[ "${prop}" = "$property=$value" ]]; then
-      echo -E - " ${unit}"
+  local props
+  for props in ${(ps:\n\n:)"$(_call_program units "$service show --no-pager --property="Id,$property" -- ${units} 2>/dev/null")"}; do
+    props=(${(f)props})
+    if [[ "${props[2]}" = "$property=$value" ]]; then
+      echo -E - " ${props[1]#Id=}"
     fi
   done
 }