47313b1
From fef18888ca215c0600b95cd4dfd9b469c9936043 Mon Sep 17 00:00:00 2001
b397f2a
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
b397f2a
Date: Wed, 29 Oct 2014 23:06:58 -0400
b397f2a
Subject: [PATCH] bash-completion: use improved filtering to make things faster
b397f2a
b397f2a
(cherry picked from commit 372b221166eb586c4f767969f442ed940e21f353)
b397f2a
---
b397f2a
 shell-completion/bash/systemctl.in | 16 +++++++++++-----
b397f2a
 1 file changed, 11 insertions(+), 5 deletions(-)
b397f2a
b397f2a
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
b397f2a
index 9e538a9a5b..9e98a1850e 100644
b397f2a
--- a/shell-completion/bash/systemctl.in
b397f2a
+++ b/shell-completion/bash/systemctl.in
b397f2a
@@ -60,14 +60,20 @@ __get_active_units   () { __systemctl $1 list-units       \
b397f2a
         | { while read -r a b; do echo " $a"; done; }; }
b397f2a
 __get_startable_units () {
b397f2a
         # find startable inactive units
b397f2a
-        __filter_units_by_property $mode LoadState loaded $(
b397f2a
-            __filter_units_by_property $mode ActiveState inactive $(
b397f2a
-                __filter_units_by_property $mode CanStart yes $( __get_all_units )))
b397f2a
+        __filter_units_by_property $mode ActiveState inactive $(
b397f2a
+            __filter_units_by_property $mode CanStart yes $(
b397f2a
+                __systemctl $mode list-unit-files --state enabled,disabled,static | \
b397f2a
+                    { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
b397f2a
+                __systemctl $mode list-units --state inactive,failed | \
b397f2a
+                    { while read -r a b; do echo " $a"; done; } ))
b397f2a
 }
b397f2a
 __get_restartable_units () {
b397f2a
         # filter out masked and not-found
b397f2a
-        __filter_units_by_property $mode LoadState loaded $(
b397f2a
-            __filter_units_by_property $mode CanStart yes $( __get_all_units ))
b397f2a
+        __filter_units_by_property $mode CanStart yes $(
b397f2a
+            __systemctl $mode list-unit-files --state enabled,disabled,static | \
b397f2a
+                    { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
b397f2a
+            __systemctl $mode list-units | \
b397f2a
+                    { while read -r a b; do echo " $a"; done; } )
b397f2a
 }
b397f2a
 __get_failed_units   () { __systemctl $1 list-units       \
b397f2a
         | { while read -r a b c d; do [[ $c == "failed"   ]] && echo " $a"; done; }; }