From ff728637cc5013e3b58b4fa5c6cf39e662c5474b Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 30 Apr 2018 13:37:51 +0100 Subject: [PATCH] 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 --- shell-completion/zsh/_systemctl.in | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index 000b585..2bb2fff 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 -- 2.7.4