|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
From 147a1201a526b3eac5ee6b0add543d5061db9943 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
Date: Wed, 29 Oct 2014 22:25:33 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
Subject: [PATCH] bash-completion: rework startable/restartable units once more
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
I tried to use 'systemctl --all list-units' to filter unit files, but
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
this always filters out unit files which are not loaded. We want to complete
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
systemctl start with those units too, so this approach is not going to work.
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
New version is rather slow, but hopefully correct.
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
(cherry picked from commit 9ff8af5460d57dfab78a1137ec743b539715e82a)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
shell-completion/bash/systemctl.in | 27 ++++++++++++++-------------
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
1 file changed, 14 insertions(+), 13 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
index 1c44a8df01..9e538a9a5b 100644
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
--- a/shell-completion/bash/systemctl.in
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+++ b/shell-completion/bash/systemctl.in
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
@@ -52,20 +52,23 @@ __filter_units_by_property () {
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
__get_all_units () { { __systemctl $1 list-unit-files; __systemctl $1 list-units --all; } \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- | { while read -r a b; do echo " $a"; done; }; }
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ | { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }; }
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
__get_template_names () { __systemctl $1 list-unit-files \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
| { while read -r a b; do [[ $a =~ @\. ]] && echo " ${a%%@.*}@"; done; }; }
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
__get_active_units () { __systemctl $1 list-units \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
| { while read -r a b; do echo " $a"; done; }; }
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
__get_startable_units () {
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- # find inactive or failed units, filter out masked and not-found
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- __systemctl $1 list-units --state inactive,failed -- $( __get_all_units ) | \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- { while read -r a b c d; do [[ $b == "loaded" ]] && echo " $a"; done; }; }
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ # find startable inactive units
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ __filter_units_by_property $mode LoadState loaded $(
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ __filter_units_by_property $mode ActiveState inactive $(
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ __filter_units_by_property $mode CanStart yes $( __get_all_units )))
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
__get_restartable_units () {
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- # find !masked, filter out masked and not-found
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- __systemctl $1 list-units --state active,inactive,failed -- $( __get_all_units ) | \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- { while read -r a b c d; do [[ $b == "loaded" ]] && echo " $a"; done; }; }
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ # filter out masked and not-found
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ __filter_units_by_property $mode LoadState loaded $(
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ __filter_units_by_property $mode CanStart yes $( __get_all_units ))
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
__get_failed_units () { __systemctl $1 list-units \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
| { while read -r a b c d; do [[ $c == "failed" ]] && echo " $a"; done; }; }
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
__get_enabled_units () { __systemctl $1 list-unit-files \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
@@ -186,15 +189,13 @@ _systemctl () {
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
compopt -o filenames
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- comps=$( __filter_units_by_property $mode CanStart yes \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- $( __get_startable_units $mode);
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- __get_template_names $mode)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ comps=$( __get_startable_units $mode;
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ __get_template_names $mode)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
compopt -o filenames
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- comps=$( __filter_units_by_property $mode CanStart yes \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- $( __get_restartable_units $mode); \
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- __get_template_names $mode)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ comps=$( __get_restartable_units $mode;
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ __get_template_names $mode)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
compopt -o filenames
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
|