]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
zsh-completion: systemctl: pass only $PREFIX* to list-unit*
authorEmil Velikov <emil.velikov@collabora.com>
Mon, 30 Apr 2018 12:37:51 +0000 (13:37 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Mon, 11 Jun 2018 16:09:56 +0000 (17:09 +0100)
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 <emil.velikov@collabora.com>
shell-completion/zsh/_systemctl.in

index 000b58560b24d79879778e9e064578d2a7c58d5d..2bb2fff376f6a107d691fa82eb49f7d06ab8f990 100644 (file)
@@ -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