diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2008-11-09 21:37:34 +0100 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2008-11-09 21:40:17 +0100 |
commit | def54e82a10697dda633772b874724bd1fb600b8 (patch) | |
tree | ad8ad209c5faec726f77de67ccbfc88916eaebdd /etc/completions | |
parent | 5a9007cdcc20c7579bbe7d04689a217caed1b536 (diff) |
initd completion: more granular matches
Complete only those scripts that actually have the particular action
Diffstat (limited to 'etc/completions')
-rw-r--r-- | etc/completions/_initd | 20 |
1 files changed, 11 insertions, 9 deletions
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 <derf@derf.homelinux.org> -## 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 |