Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: completion function for apachectl
- X-seq: zsh-workers 13531
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: completion function for apachectl
- Date: Mon, 26 Feb 2001 11:13:19 +0100 (MET)
- In-reply-to: Fletch's message of 23 Feb 2001 10:07:14 -0500
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Fletch wrote:
> This completes for apachectl (a utility that comes with apache
> to do things such as restarting apache, syntax checking it's
> configuration file, and the like).
Thanks for writing a new completion function.
Just some comments:
> +#compdef apachectl
> +
> +local curcontext="$curcontext" state line commands ret=1
> +typeset -A opt_args
Most of these need only be made local if `_arguments' is used with a
`->state' action.
> +commands=( start startssl stop restart fullstatus status
> + graceful configtest help )
Using an extra array maybe slightly more readable, but in a function
as simple as this one...
> +_arguments \
> + ":Choose an action:($commands)" && ret=0
> +
> +return $ret
No need for `&& ret=0 ... return $ret'. Without a `return' the return
value of a function is the return value of the last command in it.
And using `_arguments' is only really useful if there is some more to
do (options, multiple arguments,...) -- otherwise it's quite
expensive.
One could get the same with the simpler:
#compdef apachectl
local expl
if [[ CURRENT -eq 2 ]]; then
_wanted commands expl command compadd \
start startssl stop restart fullstatus status graceful configtest help
else
_message 'no more arguments'
fi
Hm. Since there are several commands (and scripts[1]) that only get one
command as argument, I'm almost tempted to add a generic version of
the above as a utility function. Opinions?
Bye
Sven
[1] Wasn't there a request for init-script completion on the debian list?
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author