mirror of git://git.code.sf.net/p/zsh/code
43713: Improve init.d command completion
This commit is contained in:
parent
079f7f9d48
commit
07d06c9fb9
|
@ -1,3 +1,8 @@
|
|||
2018-10-22 dana <dana@dana.is>
|
||||
|
||||
* 43713: Completion/Unix/Command/_init_d: Improve completion of
|
||||
service commands
|
||||
|
||||
2018-10-17 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 43694: Doc/Zsh/redirect.yo: More detail on how multio file
|
||||
|
|
|
@ -80,15 +80,29 @@ else
|
|||
(( $+functions[_init_d_get_cmds] )) ||
|
||||
_init_d_get_cmds() {
|
||||
local what magic cmds
|
||||
|
||||
# If the file starts with `#!' we hope that this is a shell script
|
||||
# and get lines looking like <space>foo|bar) with the words in $what.
|
||||
|
||||
what='(st(art|op|atus)|(force-|)re(start|load)|debug_(up|down)|dump(|_stats)|add|delete|clean|list)'
|
||||
local -a tmp
|
||||
|
||||
[[ -x $script ]] || return 1
|
||||
read -u0 -k2 magic < $script && [[ $magic = '#!' ]] &&
|
||||
cmds=( ${${(j:|:s:|:)${(M)${(f)"$(< $script)"}:#[[:blank:]]#(\'|)${~what}([[:blank:]]#\|[[:blank:]]#${~what})#(\'|)\)}}//[^-a-z_]} )
|
||||
|
||||
# If the file starts with `#!' we hope that this is a shell script
|
||||
# and get lines looking like <space>foo|bar) with the words in $what. Note
|
||||
# that we'll fail to match if any of the alternate patterns in the case
|
||||
# clause are not enumerated (e.g., `start|stop|custom)` won't match)
|
||||
tmp=(
|
||||
status add delete clean list
|
||||
load save show check {config,}test
|
||||
standalone master graceful
|
||||
debug debug{_,-}{up,down} dump{,{_,-}stats}
|
||||
{force-,graceful-,try-,}{start,stop,restart,reload}
|
||||
{start,stop}-htcacheclean
|
||||
)
|
||||
what="((['\"]|)(${(j<|>)tmp})(['\"]|))"
|
||||
|
||||
read -u0 -k2 magic < $script && [[ $magic = '#!' ]] && {
|
||||
cmds=( ${(f)"$(< $script)"} )
|
||||
cmds=( ${(M)cmds:#[[:blank:]]#${~what}([[:blank:]]#\|[[:blank:]]#${~what})#[[:blank:]]#\)} )
|
||||
cmds=( ${${(j:|:s:|:)cmds}//[^-a-z_]} )
|
||||
}
|
||||
|
||||
# This would be the pattern to use every line of the form <space>foo).
|
||||
# Some people say this might match too many lines...
|
||||
|
|
Loading…
Reference in New Issue