From 4ed141166c8b3a633ca7b5e15828071dce63eab0 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 11 Jun 2018 11:53:08 +0100 Subject: zsh-completion: systemctl: list template units only as needed 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 --- shell-completion/zsh/_systemctl.in | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'shell-completion') diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index 173e815a19..9f576ed77d 100644 --- a/shell-completion/zsh/_systemctl.in +++ b/shell-completion/zsh/_systemctl.in @@ -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() { -- cgit v1.2.2