Skip to content

Commit 283f3bd

Browse files
mrc0mmandbluca
authored andcommitted
shell-completion: include units in 'verify' completions
Resolves: #28500
1 parent b9e39e1 commit 283f3bd

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

shell-completion/bash/systemd-analyze

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ __get_machines() {
3333
}
3434

3535
__get_units_all() {
36-
systemctl list-units --no-legend --no-pager --plain --all | \
36+
systemctl list-units --no-legend --no-pager --plain --all $1 | \
3737
{ while read -r a b c; do echo " $a"; done }
3838
}
3939

@@ -91,6 +91,12 @@ _systemd_analyze() {
9191
fi
9292
done
9393

94+
if __contains_word "--user" ${COMP_WORDS[*]}; then
95+
mode=--user
96+
else
97+
mode=--system
98+
fi
99+
94100
if __contains_word "$prev" ${OPTS[ARG]}; then
95101
case $prev in
96102
--host|-H)
@@ -121,7 +127,7 @@ _systemd_analyze() {
121127
if [[ $cur = -* ]]; then
122128
comps='--help --version --system --user --fuzz --no-pager'
123129
else
124-
comps=$( __get_units_all )
130+
comps=$( __get_units_all $mode )
125131
fi
126132

127133
elif __contains_word "$verb" ${VERBS[DOT]}; then
@@ -133,7 +139,7 @@ _systemd_analyze() {
133139
if [[ $cur = -* ]]; then
134140
comps='--help --version --system --user --no-pager'
135141
else
136-
comps=$( __get_units_all )
142+
comps=$( __get_units_all $mode )
137143
fi
138144

139145
elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
@@ -147,7 +153,8 @@ _systemd_analyze() {
147153
if [[ $cur = -* ]]; then
148154
comps='--help --version --system --user --global --man=no --generators=yes --root --image --recursive-errors=no --recursive-errors=yes --recursive-errors=one'
149155
else
150-
comps=$( compgen -A file -- "$cur" )
156+
comps=$( compgen -A file -- "$cur";
157+
__get_units_all $mode )
151158
compopt -o filenames
152159
fi
153160

@@ -166,11 +173,6 @@ _systemd_analyze() {
166173
if [[ $cur = -* ]]; then
167174
comps='--help --version --no-pager --system --user -H --host -M --machine --offline --threshold --security-policy --json=off --json=pretty --json=short --root --image --profile=default --profile=nonetwork --profile=strict --profile=trusted'
168175
elif ! __contains_word "--offline" ${COMP_WORDS[*]}; then
169-
if __contains_word "--user" ${COMP_WORDS[*]}; then
170-
mode=--user
171-
else
172-
mode=--system
173-
fi
174176
comps=$( __get_services $mode )
175177
else
176178
comps="$CONFIGS $( compgen -A file -- "$cur" )"
@@ -181,11 +183,6 @@ _systemd_analyze() {
181183
if [[ $cur = -* ]]; then
182184
comps='--help --version --system --user --global --no-pager --root --image'
183185
elif [[ $prev = "-u" ]] || [[ $prev = "--unit" ]]; then
184-
if __contains_word "--user" ${COMP_WORDS[*]}; then
185-
mode=--user
186-
else
187-
mode=--system
188-
fi
189186
comps=$( __get_services $mode )
190187
fi
191188

0 commit comments

Comments
 (0)