#compdef Start Restart Stop Reload ## vim:ft=zsh typeset arguments file bang typeset action=${service:l} typeset -a scripts # 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##*/} } _wanted script expl script compadd $scripts