]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shell-completion: systemctl: pass current word to all list_unit*
authorEmil Velikov <emil.velikov@collabora.com>
Thu, 7 Jun 2018 15:24:45 +0000 (16:24 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Mon, 11 Jun 2018 16:09:58 +0000 (17:09 +0100)
Earlier patch added the current word to the performance critical paths.
Here we add it to every place, for consistency sake.

Suggested-by: Yu Watanabe (yuwata)
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
shell-completion/bash/systemctl.in
shell-completion/zsh/_systemctl.in

index 28981c2a74fc311cb8097d4cb407a5c613b2c310..4ff76d87fcd81eb2aff574556b9ba3e002af3824 100644 (file)
@@ -61,9 +61,9 @@ __filter_units_by_properties () {
         done
 }
 
-__get_all_units      () { { __systemctl $1 list-unit-files; __systemctl $1 list-units --all; } \
+__get_all_units      () { { __systemctl $1 list-unit-files "$2*"; __systemctl $1 list-units --all "$2*"; } \
         | { while read -r a b; do echo " $a"; done; }; }
-__get_non_template_units() { { __systemctl $1 list-unit-files; __systemctl $1 list-units --all; } \
+__get_non_template_units() { { __systemctl $1 list-unit-files "$2*"; __systemctl $1 list-units --all "$2*"; } \
         | { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }; }
 __get_template_names () { __systemctl $1 list-unit-files "$2*" \
         | { while read -r a b; do [[ $a =~ @\. ]] && echo " ${a%%@.*}@"; done; }; }
@@ -95,7 +95,7 @@ __get_disabled_units () { __systemctl $1 list-unit-files "$2*" \
         | { while read -r a b c  ; do [[ $b == "disabled" ]] && echo " $a"; done; }; }
 __get_masked_units   () { __systemctl $1 list-unit-files "$2*" \
         | { while read -r a b c  ; do [[ $b == "masked"   ]] && echo " $a"; done; }; }
-__get_all_unit_files () { { __systemctl $1 list-unit-files; } | { while read -r a b; do echo " $a"; done; }; }
+__get_all_unit_files () { { __systemctl $1 list-unit-files "$2*"; } | { while read -r a b; do echo " $a"; done; }; }
 
 __get_machines() {
         local a b
@@ -212,11 +212,11 @@ _systemctl () {
                 comps="${VERBS[*]}"
 
         elif __contains_word "$verb" ${VERBS[ALL_UNITS]}; then
-                comps=$( __get_all_units $mode )
+                comps=$( __get_all_units $mode "$cur" )
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[NONTEMPLATE_UNITS]}; then
-                comps=$( __get_non_template_units $mode )
+                comps=$( __get_non_template_units $mode "$cur" )
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[ENABLED_UNITS]}; then
@@ -256,7 +256,7 @@ _systemctl () {
 
         elif __contains_word "$verb" ${VERBS[ISOLATABLE_UNITS]}; then
                 comps=$( __filter_units_by_property $mode AllowIsolate yes \
-                      $( __get_all_units $mode ) )
+                      $( __get_all_units $mode "$cur" ) )
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[FAILED_UNITS]}; then
@@ -270,10 +270,10 @@ _systemctl () {
         elif __contains_word "$verb" ${VERBS[TARGET_AND_UNITS]}; then
                 if __contains_word "$prev" ${VERBS[TARGET_AND_UNITS]} \
                 || __contains_word "$prev" ${OPTS[STANDALONE]}; then
-                        comps=$( __systemctl $mode list-unit-files --type target --all \
+                        comps=$( __systemctl $mode list-unit-files --type target --all "$cur*" \
                         | { while read -r a b; do echo " $a"; done; } )
                 else
-                        comps=$( __get_all_unit_files $mode )
+                        comps=$( __get_all_unit_files $mode "$cur" )
                 fi
                 compopt -o filenames
 
@@ -293,7 +293,7 @@ _systemctl () {
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[TARGETS]}; then
-                comps=$( __systemctl $mode list-unit-files --type target --full --all \
+                comps=$( __systemctl $mode list-unit-files --type target --full --all "$cur*" \
                         | { while read -r a b; do echo " $a"; done; } )
         fi
 
index 9ade70b820ff2ce6366f9af6cc6209383a16c735..e49129b902591d92a2c648b09417090b24527045 100644 (file)
@@ -106,7 +106,7 @@ _systemctl_all_units()
   if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS$_sys_service_mgr ) ||
     ! _retrieve_cache SYS_ALL_UNITS$_sys_service_mgr;
   then
-    _sys_all_units=( ${${(f)"$(__systemctl list-units --all)"}%% *} )
+    _sys_all_units=( ${${(f)"$(__systemctl list-units --all "$PREFIX*" )"}%% *} )
     _store_cache SYS_ALL_UNITS$_sys_service_mgr _sys_all_units
   fi
 }
@@ -119,7 +119,7 @@ _systemctl_really_all_units()
   if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS$_sys_service_mgr ) ||
     ! _retrieve_cache SYS_REALLY_ALL_UNITS$_sys_service_mgr;
   then
-    all_unit_files=( ${${(f)"$(__systemctl list-unit-files)"}%% *} )
+    all_unit_files=( ${${(f)"$(__systemctl list-unit-files "$PREFIX*" )"}%% *} )
     _systemctl_all_units
     really_all_units=($_sys_all_units $all_unit_files)
     _sys_really_all_units=(${(u)really_all_units})
@@ -270,7 +270,7 @@ done
 (( $+functions[_systemctl_set-default] )) || _systemctl_set-default()
 {
   _wanted systemd-targets expl target \
-    compadd "$@" - ${${(f)"$(__systemctl list-unit-files --type target --all)"}%% *} ||
+    compadd "$@" - ${${(f)"$(__systemctl list-unit-files --type target --all "$PREFIX*" )"}%% *} ||
       _message "no targets found"
 }