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

Re: Redirection completion



Peter Stephenson wrote:

> ...
> 
> Is the patch at the end useful?  I got caught out because I originally
> defined a completion for a non-existent type `redir'.  The list of types
> appears to be closed --- i.e. you can't add your own because they're
> handled internally --- in which case it's safe to test the type.

Yes and no.  In its last incarnation, the types are completely defined
by the functions making use of them. compinit/compdef collects them
from the -T options it gets.

So, for the time being, the patch below is (almost) fine.  I was
thinking about people who might want to stuff calls to compdef into
the startup files and later (somehow) make the functions known that
use those completion types.  Maybe that's not really an issue, my
brain was getting pretty fuzzy at that time.

Anyway, `almost' because compdef updates the array _comp_assocs to
contain all completion type names it knows about, so the patch should
use that.

> Next, it looks like the context for redirections isn't all that helpful
> at the moment.  After `echo 2>' I seem to get just
> `:completion::complete:echo::'.  Could we have something like the way
> arguments work, so that it at least indicates we're in a redirection,
> and preferably also the `2>' bit?  Along the lines of
>   :completion::complete:dvips:option-o-1:
> I would suggest
>   :completion::complete:echo:redir-2>:'
> for `echo 2>'.

Hm, yes.  The strings given to _dispatch are currently only used for
lookup-as-in-command-name-lookup, not for context name lookup.  And
for redirections we use `command:op', so you can do e.g.:

  compdef '_files -g "*.log"' -T redirs 'echo:2>'
  compdef '_files -g "*.log"' -T redirs 'echo:2>|'

This should also work with pattern-completions... but not with a line
like the ones above, because _dispatch doesn't use eval for pattern
completions.  I've overlooked that and will produce a patch till next
week, together with a patch for:

I wasn't sure about using a colon to separate the command name from
the redirection operator anyway, but I simply forgot to stuff the
information into the context string.  That's a good idea, I'll do that
and put the fix with the missing `eval's into the same patch (should I
also include the change to make compdef() use _comp_assocs? saving you
some time?)

> ...
> 
> This always prefers log files, and it would probably be nicer to use
> _alternative.  But then I need a tag order to make sure they don't all
> get shown at once, and for that I need a context.  At least, I think.
> Thinking some more, I could probably do all this more easily with
> file-patterns, but that definitely requires more specific context
> information.)

Right.

> By the way, I think I'm going to expand the user guide to include more
> recipe-style information.  If anyone wants to send me a list of stuff
> that can be done that's not described at the moment (see
> http://zsh.sunsite.dk/Guide/zshguide06.html) I'll add it.

Sounds good, no ideas yet, will try to think of some...


Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@xxxxxxxxx



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