mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-07 17:17:44 +03:00
zsh: reintroduce pattern argument to uncached verbs
The systemctl completion previously made use of PREFIX as a pattern
argument to list-unit-files and list-units. This had the problem of
erroneously filtering the results that were stored in the cache, and
erroneously filtering results that might have been requested according
to the users configuration (e.g. _correct completer, certain
matcher-lists or tag-orders, etc.).
Unfortunately, the runtime of list-unit-files increases when no pattern
argument is provided, and systemctl show, used to filter those units,
can become unacceptably slow when provided with too many units to
describe.
Let's re-introduce the pattern argument to list-unit-files and
list-units where necessary in order to alleviate these bottlenecks
without poisining the cache. A 'use-pattern' style is introduced that
may be used to disable this behavior if it is undesired. We can still
expect that certain completions, like `systemctl start <TAB>` will be
slow, like before. To fix this we will need systemd to learn a more
efficient way of filtering the units than parsing systemctl show.
(cherry picked from commit 2cbda74862
)
This commit is contained in:
parent
9814972198
commit
dfc0445cb8
@ -206,23 +206,37 @@ __systemctl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
(( $+functions[_systemctl_active_units] )) ||
|
(( $+functions[_systemctl_active_units] )) ||
|
||||||
_systemctl_active_units() {_sys_active_units=( ${${(f)"$(__systemctl list-units)"}%% *} )}
|
_systemctl_active_units() {
|
||||||
|
local pattern
|
||||||
|
if zstyle -T ":completion:$curcontext" use-pattern; then
|
||||||
|
pattern="$PREFIX*$SUFFIX"
|
||||||
|
fi
|
||||||
|
_sys_active_units=( ${${(f)"$(__systemctl list-units $pattern)"}%% *} )
|
||||||
|
}
|
||||||
|
|
||||||
(( $+functions[_systemctl_startable_units] )) ||
|
(( $+functions[_systemctl_startable_units] )) ||
|
||||||
_systemctl_startable_units(){
|
_systemctl_startable_units(){
|
||||||
|
local pattern
|
||||||
|
if zstyle -T ":completion:$curcontext" use-pattern; then
|
||||||
|
pattern="$PREFIX*$SUFFIX"
|
||||||
|
fi
|
||||||
_sys_startable_units=( $( _filter_units_by_property ActiveState inactive $(
|
_sys_startable_units=( $( _filter_units_by_property ActiveState inactive $(
|
||||||
_filter_units_by_property CanStart yes ${${${(f)"$(
|
_filter_units_by_property CanStart yes ${${${(f)"$(
|
||||||
__systemctl list-unit-files --state enabled,enabled-runtime,linked,linked-runtime,static,indirect,disabled,generated,transient
|
__systemctl list-unit-files --state enabled,enabled-runtime,linked,linked-runtime,static,indirect,disabled,generated,transient $pattern
|
||||||
__systemctl list-units --state inactive,failed
|
__systemctl list-units --state inactive,failed $pattern
|
||||||
)"}:#*@.*}%%[[:space:]]*}
|
)"}:#*@.*}%%[[:space:]]*}
|
||||||
)) )
|
)) )
|
||||||
}
|
}
|
||||||
|
|
||||||
(( $+functions[_systemctl_restartable_units] )) ||
|
(( $+functions[_systemctl_restartable_units] )) ||
|
||||||
_systemctl_restartable_units(){
|
_systemctl_restartable_units(){
|
||||||
|
local pattern
|
||||||
|
if zstyle -T ":completion:$curcontext" use-pattern; then
|
||||||
|
pattern="$PREFIX*$SUFFIX"
|
||||||
|
fi
|
||||||
_sys_restartable_units=( $( _filter_units_by_property CanStart yes ${${${(f)"$(
|
_sys_restartable_units=( $( _filter_units_by_property CanStart yes ${${${(f)"$(
|
||||||
__systemctl list-unit-files --state enabled,disabled,static
|
__systemctl list-unit-files --state enabled,disabled,static $pattern
|
||||||
__systemctl list-units
|
__systemctl list-units $pattern
|
||||||
)"}:#*@.*}%%[[:space:]]*} ) )
|
)"}:#*@.*}%%[[:space:]]*} ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,8 +246,12 @@ __systemctl()
|
|||||||
(( $+functions[_systemctl_unit_state] )) ||
|
(( $+functions[_systemctl_unit_state] )) ||
|
||||||
_systemctl_unit_state() {
|
_systemctl_unit_state() {
|
||||||
setopt localoptions extendedglob
|
setopt localoptions extendedglob
|
||||||
|
local pattern
|
||||||
|
if zstyle -T ":completion:$curcontext" use-pattern; then
|
||||||
|
pattern="$PREFIX*$SUFFIX"
|
||||||
|
fi
|
||||||
typeset -gA _sys_unit_state
|
typeset -gA _sys_unit_state
|
||||||
_sys_unit_state=( ${=${${(f)"$(__systemctl list-unit-files)"}%%[[:space:]]#}% *} )
|
_sys_unit_state=( ${=${${(f)"$(__systemctl list-unit-files $pattern)"}%%[[:space:]]#}% *} )
|
||||||
}
|
}
|
||||||
|
|
||||||
local fun
|
local fun
|
||||||
|
Loading…
Reference in New Issue
Block a user