From def54e82a10697dda633772b874724bd1fb600b8 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 9 Nov 2008 21:37:34 +0100 Subject: initd completion: more granular matches Complete only those scripts that actually have the particular action --- etc/completions/_initd | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'etc') diff --git a/etc/completions/_initd b/etc/completions/_initd index 3507117..52dd91b 100644 --- a/etc/completions/_initd +++ b/etc/completions/_initd @@ -1,14 +1,16 @@ #compdef Start Restart Stop Reload ## vim:ft=zsh -## Completion for /etc/init.d functions -## Daniel Friesel -## https://derf.homelinux.org/~derf/dotfiles/completion/_initd -## see also: https://derf.homelinux.org/~derf/dotfiles/zsh/function -local arguments +typeset arguments file bang +typeset action=${service:l} +typeset -a scripts -arguments=( - ':file:_path_files -W /etc/init.d -g "*(*)"' -) +# Most of the loop's content has been taken from the _init_d +# completion function provided with zsh +for file in /etc/init.d/*(*); { + read -u0 -k2 bang < $file && [[ $bang == '#!' ]] && + [[ -n ${${(j:|:s:|:)${(M)${(f)"$(< $file)"}:#[[:blank:]]#(\'|)${~action}([[:blank:]]#\|[[:blank:]]#${~action})#(\'|)\)}}//[^-a-z_]} ]] && + scripts+=${file##*/} +} -_arguments -s $arguments +_wanted script expl script compadd $scripts -- cgit v1.2.3