]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
zsh-completion: systemctl: list template units only as needed 8863/head
authorEmil Velikov <emil.velikov@collabora.com>
Mon, 11 Jun 2018 10:53:08 +0000 (11:53 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Mon, 11 Jun 2018 18:02:36 +0000 (19:02 +0100)
Currently the completion adds template units for commands such as
is-active, is-failed, is-enabled, status, show and others.

At the same time systemctl barfs at us, since an instanced template unit
is needed. Follow the example list from bash-completion as to which
commands should not list template units.

Note: The above is observed regardless of DefaultInstance.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
shell-completion/zsh/_systemctl.in

index 173e815a1996b86edd4e2ec456daf49c86dbd418..9f576ed77d862b3823a096e59f44763e60d2f46f 100644 (file)
@@ -135,6 +135,11 @@ _filter_units_by_property() {
   echo -E - "${(@g:o:)${(k@)props[(Re)$property=$value]}#Id=}"
 }
 
+_systemctl_get_non_template_names() { echo -E - ${^${(R)${(f)"$(
+    __systemctl $mode list-unit-files "$PREFIX*"
+    __systemctl $mode list-units --all "$PREFIX*"
+  )"}:#*@.*}%%[[:space:]]*} }
+
 _systemctl_get_template_names() { echo -E - ${^${(M)${(f)"$(__systemctl list-unit-files "$PREFIX*" )"}##*@.[^[:space:]]##}%%@.*}\@ }
 
 
@@ -161,7 +166,7 @@ _systemctl_unit_state() { typeset -gA _sys_unit_state; _sys_unit_state=( $(__sys
 
 local fun
 # Completion functions for ALL_UNITS
-for fun in is-active is-failed is-enabled status show cat mask preset help list-dependencies edit revert add-wants add-requires ; do
+for fun in cat mask ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
     _systemctl_really_all_units
@@ -170,6 +175,15 @@ for fun in is-active is-failed is-enabled status show cat mask preset help list-
   }
 done
 
+# Completion functions for NONTEMPLATE_UNITS
+for fun in is-active is-failed is-enabled status show preset help list-dependencies edit revert add-wants add-requires ; do
+  (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
+  {
+    _wanted systemd-units expl unit \
+      compadd "$@" - $(_systemctl_get_non_template_names)
+  }
+done
+
 # Completion functions for ENABLED_UNITS
 (( $+functions[_systemctl_disable] )) || _systemctl_disable()
 {