systemd/0017-bash-completion-use-th...

74 lines
3.4 KiB
Diff

From f6441eaf050267c05ef8df8d5614bb598528942f Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Thu, 27 Jul 2017 20:22:54 +0900
Subject: [PATCH] bash-completion: use the first argument instead of the global
variable (#6457)
Without this fix:
$ systemctl start <tab>
Display all 135 possibilities? (y or n)
$ __get_startable_units --system | wc -l
224
the number of the suggestions are quite different, as __get_startable_units --system does
not filter already started units. With this fix,
$ systemctl start <tab>
Display all 135 possibilities? (y or n)
$ __get_startable_units --system | wc -l
123
$ __get_template_names --system | wc -l
12
the number of the suggestions matches one the function returns.
For consistency with the other internal functions, it should use the first argument
instead of the global variable $mode.
[zj: add commit message to make it sound like we know what we're doing]
(cherry picked from commit 6bda23dd6aaba50cf8e3e6024248cf736cc443ca)
---
shell-completion/bash/systemctl.in | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index 0398d09d18..bde28efc3e 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -68,7 +68,7 @@ __filter_units_by_properties () {
done
for ((i=0; i < ${#units[*]}; i++)); do
for ((j=0; j < ${#conditions[*]}; j++)); do
- if [[ "${props[ i * ${#conditions[*]} + j]}" != "${conditions[j]}" ]]; then
+ if [[ "${props[i * ${#conditions[*]} + j]}" != "${conditions[j]}" ]]; then
break
fi
done
@@ -87,19 +87,19 @@ __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_properties $mode ActiveState,CanStart inactive,yes $(
- { __systemctl $mode list-unit-files --state enabled,enabled-runtime,linked,linked-runtime,static,indirect,disabled,generated,transient | \
+ __filter_units_by_properties $1 ActiveState,CanStart inactive,yes $(
+ { __systemctl $1 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 | \
+ __systemctl $1 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
- __filter_units_by_property $mode CanStart yes $(
- __systemctl $mode list-unit-files --state enabled,disabled,static | \
+ __filter_units_by_property $1 CanStart yes $(
+ __systemctl $1 list-unit-files --state enabled,disabled,static | \
{ while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
- __systemctl $mode list-units | \
+ __systemctl $1 list-units | \
{ while read -r a b; do echo " $a"; done; } )
}
__get_failed_units () { __systemctl $1 list-units \