summaryrefslogtreecommitdiff
path: root/shell-completion
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-10-11 17:05:19 +0200
committerGitHub <noreply@github.com>2016-10-11 17:05:19 +0200
commit40f45ff0c339971fd088e6f9cc2e61444087685d (patch)
tree38f775fd15505fb69116b753307fb330b1c1b160 /shell-completion
parenta8cb1dc3e0fa81affd01c8ed3df35e4c4520a24e (diff)
parentc07c80bc969fdb745593a86c8a34758722eeb29a (diff)
Merge pull request #4115 from yuwata/completion-fix
bash-completion: systemctl: do not pass masked or not-found units to filter
Diffstat (limited to 'shell-completion')
-rw-r--r--shell-completion/bash/systemctl.in41
1 files changed, 34 insertions, 7 deletions
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index 2a45dcbba0..dcf71a1f51 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -41,7 +41,7 @@ __contains_word () {
__filter_units_by_property () {
local mode=$1 property=$2 value=$3 ; shift 3
local units=("$@")
- local props
+ local props i
IFS=$'\n' read -rd '' -a props < \
<(__systemctl $mode show --property "$property" -- "${units[@]}")
for ((i=0; $i < ${#units[*]}; i++)); do
@@ -51,6 +51,33 @@ __filter_units_by_property () {
done
}
+__filter_units_by_properties () {
+ local mode=$1 properties=$2 values=$3 ; shift 3
+ local units=("$@")
+ local props i j conditions=()
+ IFS=$'\n' read -rd '' -a props < \
+ <(__systemctl $mode show --property "$properties" -- "${units[@]}")
+ IFS=$',' read -r -a properties < <(echo $properties)
+ IFS=$',' read -r -a values < <(echo $values)
+ for ((i=0; i < ${#properties[*]}; i++)); do
+ for ((j=0; j < ${#properties[*]}; j++)); do
+ if [[ ${props[i]%%=*} == ${properties[j]} ]]; then
+ conditions+=( "${properties[j]}=${values[j]}" )
+ fi
+ done
+ done
+ for ((i=0; i < ${#units[*]}; i++)); do
+ for ((j=0; j < ${#conditions[*]}; j++)); do
+ if [[ "${props[ i * ${#conditions[*]} + j]}" != "${conditions[j]}" ]]; then
+ break
+ fi
+ done
+ if (( j == ${#conditions[*]} )); then
+ echo " ${units[i]}"
+ fi
+ done
+}
+
__get_all_units () { { __systemctl $1 list-unit-files; __systemctl $1 list-units --all; } \
| { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }; }
__get_template_names () { __systemctl $1 list-unit-files \
@@ -60,12 +87,12 @@ __get_active_units () { __systemctl $1 list-units \
| { while read -r a b; do echo " $a"; done; }; }
__get_startable_units () {
# find startable inactive units
- __filter_units_by_property $mode ActiveState inactive $(
- __filter_units_by_property $mode CanStart yes $(
- __systemctl $mode list-unit-files --state enabled,disabled,static | \
- { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
- __systemctl $mode list-units --state inactive,failed | \
- { while read -r a b; do echo " $a"; done; } ))
+ __filter_units_by_properties $mode ActiveState,CanStart inactive,yes $(
+ { __systemctl $mode list-unit-files --state enabled,enabled-runtime,linked,linked-runtime,static,indirect,disabled,generated,transient | \
+ { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
+ __systemctl $mode list-units --state inactive,failed | \
+ { while read -r a b c; do [[ $b == "loaded" ]] && echo " $a"; done; }
+ } | sort -u )
}
__get_restartable_units () {
# filter out masked and not-found