Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: _os_arguments
- X-seq: zsh-workers 40169
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: _os_arguments
- Date: Tue, 13 Dec 2016 01:54:05 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1481590446; bh=5CySOCwScvZbBzZY1Wqm4FFUDWkxXTwpu4EZ6jMiGzo=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=beqDR8TCbR6BAVKOLmxmhUsSLlnPvE/pTwUdN9y7kQCDZbafNBqhRQoGd4hvSxdwTef1ExzAXhOiLhCLbICmqqIIBKpqtdgkm4SHkCtTFx1Lwj0VZ/no6RLjWvl1JO+64yiT/mGBhr1wmBX6ePM+wOmAnMs+oR5vlda3xiphipUaU3pmZvcjJylQ0oUygC7WHo7eBsa4WC/CxP0hGcCNxoNf4WH+4BYekDsTJKxQjRQ+WeKNMzLV+q/c0Do31flHb89A4PKz3TvQiEjQF21z0xP81VLDVPAMlgO7pRc6H7j18V1J67IRKMAo9lPgLsGqd89r4T6bjn2N2Nrw+kO0MA==
- In-reply-to: <20161212052803.GA53519@CptOrmolo.darkstar>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20161212052803.GA53519@CptOrmolo.darkstar>
Matthew Martin wrote:
> When updating completions for the BSDs, it can be a bit of a pain to
> check each case or if block especially since the alphabetization of the
> options is disrupted. This is an attempt to ease that pain. First an
> example usage converting _rm to _os_arguments then the patch itself.
Have you seen the approach taken in _chown, _cp, _du and _last which
also does not disrupt the order of options? There could be ways to
compress the patterns down.
Having only a single letter and wrapping _arguments directly means that
this wouldn't work for a number of functions. We have quite a few cases
where we do:
_pick_variant -r variant gnu=GNU $OSTYPE --version
and then use $variant with the case statement.
Also, there are quite a few cases where we include the version number,
particularly with Solaris because Solaris 10 still gets a fair amount of
use (is still the primary platform where I work). I was planning to do
this somewhat more in future for BSDs (at least at major version level)
now that we've got more of the functions in a good state: it's easier
when adding them incrementally.
Rather than wrap _arguments directly, it might be more flexible to have
some sort of filter_args helper. That could also be applied around
_values too for, e.g. dd or ifconfig. It could allow for custom
letter mappings and have the option of making other transformations on
the args list before going on to _arguments. It might also be easier to
mix with _arguments' sets feature.
Long options can pose a bigger challenge when trying to handle different
systems. There are a few GNU utilities such as grep where FreeBSD and
Darwin have forked at the final GPL2 release. So I can see there being
more cases where we need to handle these with associated issues such as
sharing the latter part of the _arguments spec (description etc) between
the long and short option. I'd regard alphabetization of options to be
a lesser concern. For single implementation commands, I try to follow
the ordering from -h / --help output which is usually a mix of logical,
alphabetical and some randomness. And sometimes it'd be more helpful to
have them ordered with options that have similar mutual exclusions.
> +case $OSTYPE in
> + aix*) os=A;;
> + cygwin*) os=C;;
Note that this case statement could be done as an associative array. I
mention this mainly because an associative array is easier to extend if
we were to support that:
typeset -A osabbrev
osabbrev=( 'linux*' L 'openbsd*' O ..... )
os=${a[(k)$OSTYPE]}
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author