From: Emil Velikov Date: Mon, 30 Apr 2018 12:37:51 +0000 (+0100) Subject: zsh-completion: systemctl: pass only $PREFIX* to list-unit* X-Git-Tag: v239~78^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff728637cc5013e3b58b4fa5c6cf39e662c5474b;p=thirdparty%2Fsystemd.git zsh-completion: systemctl: pass only $PREFIX* to list-unit* Using a leading * and $SUFFIX produces misleading results. Let's imagine that one mistypes nect instead of netc, they will get a rather misleading completion like: sys-fs-fuse-connections.mount Not to mention that the execution time is up by ~1/3. time systemctl list-unit-files netctl* -> ~12ms time systemctl list-unit-files *netctl* -> ~17ms Furthermore more units are matched, leading to greater execution time of `systemctl show' in _filter_units_by_property Use only $PREFIX*, removing the leading * and trailing $SUFFIX*. Signed-off-by: Emil Velikov --- diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index 000b58560b2..2bb2fff376f 100644 --- a/shell-completion/zsh/_systemctl.in +++ b/shell-completion/zsh/_systemctl.in @@ -135,29 +135,29 @@ _filter_units_by_property() { echo -E - "${(@g:o:)${(k@)props[(Re)$property=$value]}#Id=}" } -_systemctl_get_template_names() { echo -E - ${^${(M)${(f)"$(__systemctl list-unit-files "*$PREFIX*$SUFFIX*" )"}##*@.[^[:space:]]##}%%@.*}\@ } +_systemctl_get_template_names() { echo -E - ${^${(M)${(f)"$(__systemctl list-unit-files "$PREFIX*" )"}##*@.[^[:space:]]##}%%@.*}\@ } -_systemctl_active_units() {_sys_active_units=( ${${(f)"$(__systemctl list-units "*$PREFIX*$SUFFIX*" )"}%% *} )} +_systemctl_active_units() {_sys_active_units=( ${${(f)"$(__systemctl list-units "$PREFIX*" )"}%% *} )} _systemctl_startable_units(){ _sys_startable_units=( $( _filter_units_by_property ActiveState inactive $( _filter_units_by_property CanStart yes ${${${(f)"$( - __systemctl $mode list-unit-files --state enabled,disabled,static "*$PREFIX*$SUFFIX*" - __systemctl $mode list-units --state inactive,failed "*$PREFIX*$SUFFIX*" + __systemctl $mode list-unit-files --state enabled,disabled,static "$PREFIX*" + __systemctl $mode list-units --state inactive,failed "$PREFIX*" )"}:#*@.*}%%[[:space:]]*} )) ) } _systemctl_restartable_units(){ _sys_restartable_units=( $( _filter_units_by_property CanStart yes ${${${(f)"$( - __systemctl $mode list-unit-files --state enabled,disabled,static "*$PREFIX*$SUFFIX*" - __systemctl $mode list-units "*$PREFIX*$SUFFIX*" + __systemctl $mode list-unit-files --state enabled,disabled,static "$PREFIX*" + __systemctl $mode list-units "$PREFIX*" )"}:#*@.*}%%[[:space:]]*} ) ) } -_systemctl_failed_units() {_sys_failed_units=( ${${(f)"$(__systemctl list-units --state=failed "*$PREFIX*$SUFFIX*" )"}%% *} ) } -_systemctl_unit_state() { typeset -gA _sys_unit_state; _sys_unit_state=( $(__systemctl list-unit-files "*$PREFIX*$SUFFIX*" ) ) } +_systemctl_failed_units() {_sys_failed_units=( ${${(f)"$(__systemctl list-units --state=failed "$PREFIX*" )"}%% *} ) } +_systemctl_unit_state() { typeset -gA _sys_unit_state; _sys_unit_state=( $(__systemctl list-unit-files "$PREFIX*" ) ) } local fun # Completion functions for ALL_UNITS