using _wanted instead of calling compadd directly. this allows the user to
customize
possible matches.
An example being, grouping units by type:
autoload -Uz compinit; compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' group-name ''
zstyle ':completion:*' format 'Completing %d'
zstyle -e ':completion:*:*:systemctl-(((re|)en|dis)able|(*re|)start|reload*):*'
\
tag-order 'local type; for type in service template target socket;
reply+=( systemd-units:-${type}:${type} ); reply=( $reply
systemd-units:-misc:misc )'
zstyle ':completion:*:systemd-units-template' ignored-patterns '^*@'
zstyle ':completion:*:systemd-units-target' ignored-patterns '^*.target'
zstyle ':completion:*:systemd-units-socket' ignored-patterns '^*.socket'
zstyle ':completion:*:systemd-units-service' ignored-patterns '^*.service'
zstyle ':completion:*:systemd-units-misc' ignored-patterns
'*(@|.(service|socket|target))'
also, poke
http://lists.freedesktop.org/archives/systemd-devel/2015-May/032012.html
---
shell-completion/zsh/_systemctl.in | 60 +++---
1 file changed, 37 insertions(+), 23 deletions(-)
diff --git a/shell-completion/zsh/_systemctl.in
b/shell-completion/zsh/_systemctl.in
index db9bdb6..e11671f 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -65,7 +65,7 @@
if (( CURRENT == 1 )); then
_describe -t commands 'systemctl command' _systemctl_cmds || compadd $@
else
-local curcontext=$curcontext
+local curcontext=$curcontext expl
cmd=${${_systemctl_cmds[(r)$words[1]:*]%%:*}}
# Deal with any aliases
@@ -172,7 +172,8 @@ for fun in is-active is-failed is-enabled status show cat
mask preset help list-
(( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
{
_systemctl_really_all_units
-compadd $@ -a - _sys_really_all_units
+_wanted systemd-units expl unit \
+ compadd $@ -a - _sys_really_all_units
}
done
@@ -180,34 +181,39 @@ done
(( $+functions[_systemctl_disable] )) || _systemctl_disable()
{
local _sys_unit_state; _systemctl_unit_state
-compadd $@ - ${(k)_sys_unit_state[(R)enabled]}
+_wanted systemd-units expl 'enabled unit' \
+ compadd $@ - ${(k)_sys_unit_state[(R)enabled]}
}
(( $+functions[_systemctl_reenable] )) || _systemctl_reenable()
{
local _sys_unit_state; _systemctl_unit_state
-compadd $@ - ${(k)_sys_unit_state[(R)(enabled|disabled)]}
$(_systemctl_get_template_names)
+_wanted systemd-units expl 'enabled/disabled unit' \
+ compadd $@ - ${(k)_sys_unit_state[(R)(enabled|disabled)]}
$(_systemctl_get_template_names)
}
# Completion functions for DISABLED_UNITS
(( $+functions[_systemctl_enable] )) || _systemctl_enable()
{
local _sys_unit_state; _systemctl_unit_state
- compadd $@ - ${(k)_sys_unit_state[(R)disabled]}
$(_systemctl_get_template_names)
+ _wanted systemd-units expl 'disabled unit' \
+compadd $@ - ${(k)_sys_unit_state[(R)disabled]}
$(_systemctl_get_template_names)
}
# Completion functions for FAILED_UNITS
(( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
{
local _sys_failed_units; _systemctl_failed_units
- compadd $@ -a - _sys_failed_units || _message no failed unit found
+ _wanted systemd-units expl 'failed unit' \
+compadd $@ -a - _sys_failed_units || _message no failed unit found
}
# Completion functions for STARTABLE_UNITS
(( $+functions[_systemctl_start] )) || _systemctl_start()
{
local _sys_startable_units; _systemctl_startable_units
- compadd $@ - ${_sys_startable_units[*]} $(_systemctl_get_template_names)
+ _wanted systemd-units expl 'startable unit' \
+ compadd $@ - ${_sys_startable_units[*]} $(_systemctl_get_template_names)
}
# Completion functions for STOPPABLE_UNITS
@@ -215,8 +221,9 @@ for fun in stop kill try-restart condrestart ; do
(( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
{
local _sys_active_units; _systemctl_active_units
-compadd $@ - $( _filter_units_by_property CanStop yes \
- ${_sys_active_units[*]} )
+_wanted systemd-units expl 'stoppable unit' \
+ compadd $@ - $( _filter_units_by_property CanStop yes \
+${_sys_active_units[*]} )
}
done
@@ -224,8 +231,9 @@ done
(( $+functions[_systemctl_isolate] )) || _systemctl_isolate()
{
_systemctl_all_units
- compadd $@ - $( _filter_units_by_property AllowIsolate yes \
-${_sys_all_units[*]} )
+ _wanted systemd-units expl 'isolatable unit' \
+compadd $@ - $( _filter_units_by_property AllowIsolate yes \
+ ${_sys_all_units[*]} )
}
# Completion functions for RELOADABLE_UNITS
@@ -233,8 +241,9 @@ for fun in reload reload-or-try-restart force-reload ; do
(( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
{
local _sys_active_units; _systemctl_active_units
-compadd $@ - $( _filter_units_by_property CanReload yes \
- ${_sys_active_units[*]} )
+_wanted systemd-units expl 'reloadable