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

Re: Completion for gtar



"Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx> writes:

> Have you looked at PWS's tar completion in Misc/compctl-examples in
> 3.1.4?  It even has a function to extract completable file names
> from the tar file.

No, I hadn't.  Partly deliberately---this was as much an exercise as
anything.  Now I look at it, and the two look reassuringly similar,
although PWS's provides more.

> You can just do
> 
> 	compctl -f -x 'p[1]' -k taropts -- gtar
> 
> unless you want to unset taropts and not have it hanging around.

Yes.  Or rather, I didn't want to rely on taropts sticking around.

> I don't think that means what you think it means.  If you put the "-"
> in the list of -g patterns, then it's treated as a file name.  It just
> so happens that, because it has no wildcards, it never gets dropped
> from the list of completions.  So you'll find that you can complete
> e.g. like this:
> 
> zsh% gtar zxf ~/<TAB>
> zsh% gtar zxf ~/-
> 
> even when there's no file named "-" in your home dir.

That's clearly not what I want.  You're right, there's no advantage in
having - complete to itself, so I ought to remove it.

> 	compctl -f -x 'p[1]' -k taropts \
> 	        - 'p[2] W[1,*z*]' -/g '*.tar.(gz|Z)' -k '(-)' \
> 		-- gtar
> 
> BTW, don't you want to add W[1,*f*] to that?  You don't want to complete
> file names if there's no "f" option.

I don't care about not having the f option---I never use gtar except
on files.  (Backups and so on are done differently, and by somebody
else.)

> That is what alternation is about, but alternation works differently.
> The -x branches are short-circuited on whether their patterns match, so
> once you take a -x branch you can never see completions from any of the
> other branches, even if no completions result from the branch where the
> patterns matched.
> 
> Alternation with "+", on the other hand, short-circuits on whether the
> list of possible completions is empty, so it'll keep trying until it
> runs out of alternatives or finds one that produces something.

OK.  I don't think this is clear from the documentation.  Not as clear
as the two paragraphs you've just given, anyway.



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