Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Using the same completion function for various commands



On Mon, 06 Dec 2010 08:44:28 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Dec 6,  4:21pm, Peter Stephenson wrote:
> }
> } Is the following change to _pick_variant right?  Why we would ever
> } prefer $words[1] to $service, when this seems to be what $service is
> } for?
> 
> My recollection is that $words[1] is always a command, whereas
> $service may just be a placeholder name.  However, I can't provide an
> example where this would introduce a problem for _pick_variant in
> particular.

Yes, for example in _perforce I use the service as p4-<subcommand>.
But, as you imply, in that case there's no question of running
_pick_variant, we've already got into the detailed syntax another way.

We can just pass -c $service to _pick_variants, it's just that that's
yet another variable factor to go wrong, so if we can avoid it that's
good.  In particular, you don't notice it's gone wrong until a case like
the one Mikael noticed --- to put it another way, the service is a
parameter that can be set by the user, and until the user tries to map a
new command to an existing completion you don't know the completion
function needed "-c $service".

Of course, if we find a case where this doesn't work, the caller can use
"-c $words[1]".  Given that I think that's the odd case out, maybe I'll
just commit it and see what happens.

(Sigh. Good job it's only Monday...)

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



Messages sorted by: Reverse Date, Date, Thread, Author