mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-08-04 12:22:39 +03:00
Merge pull request #4115 from yuwata/completion-fix
bash-completion: systemctl: do not pass masked or not-found units to filter
This commit is contained in:
@ -41,7 +41,7 @@ __contains_word () {
|
|||||||
__filter_units_by_property () {
|
__filter_units_by_property () {
|
||||||
local mode=$1 property=$2 value=$3 ; shift 3
|
local mode=$1 property=$2 value=$3 ; shift 3
|
||||||
local units=("$@")
|
local units=("$@")
|
||||||
local props
|
local props i
|
||||||
IFS=$'\n' read -rd '' -a props < \
|
IFS=$'\n' read -rd '' -a props < \
|
||||||
<(__systemctl $mode show --property "$property" -- "${units[@]}")
|
<(__systemctl $mode show --property "$property" -- "${units[@]}")
|
||||||
for ((i=0; $i < ${#units[*]}; i++)); do
|
for ((i=0; $i < ${#units[*]}; i++)); do
|
||||||
@ -51,6 +51,33 @@ __filter_units_by_property () {
|
|||||||
done
|
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; } \
|
__get_all_units () { { __systemctl $1 list-unit-files; __systemctl $1 list-units --all; } \
|
||||||
| { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }; }
|
| { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }; }
|
||||||
__get_template_names () { __systemctl $1 list-unit-files \
|
__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; }; }
|
| { while read -r a b; do echo " $a"; done; }; }
|
||||||
__get_startable_units () {
|
__get_startable_units () {
|
||||||
# find startable inactive units
|
# find startable inactive units
|
||||||
__filter_units_by_property $mode ActiveState inactive $(
|
__filter_units_by_properties $mode ActiveState,CanStart inactive,yes $(
|
||||||
__filter_units_by_property $mode CanStart yes $(
|
{ __systemctl $mode list-unit-files --state enabled,enabled-runtime,linked,linked-runtime,static,indirect,disabled,generated,transient | \
|
||||||
__systemctl $mode list-unit-files --state enabled,disabled,static | \
|
{ while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
|
||||||
{ while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
|
__systemctl $mode list-units --state inactive,failed | \
|
||||||
__systemctl $mode list-units --state inactive,failed | \
|
{ while read -r a b c; do [[ $b == "loaded" ]] && echo " $a"; done; }
|
||||||
{ while read -r a b; do echo " $a"; done; } ))
|
} | sort -u )
|
||||||
}
|
}
|
||||||
__get_restartable_units () {
|
__get_restartable_units () {
|
||||||
# filter out masked and not-found
|
# filter out masked and not-found
|
||||||
|
Reference in New Issue
Block a user