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

Re: Redirection completion



Sven wrote:

> Whew.  Thinking some more lead to the patch below which is probably
> entirely different from what everyone expected.  It removes the -T
> completion type handling again.  Ahem.  Let me explain.

This is better. Certainly, it wasn't what I was expecting though I was
thinking that it was unfortunate that we were inconsistent with words we
were using (redirs vs. -redirect- etc). After more thought I was also
further convinced about using the command part of the context to
describe the dispatch key.

I've tried yesterdays patch and things don't seem to be quite working
yet - I'm just getting file completion. I also had limited success with
pattern completions for values and the old -T system. I've put one at
the end. If you fix it, please commit it yourself. I perhaps just
needed those new -p and -N changes which I was going to suggest.

I also got _gzip to handle GZIP which I'll post once you've got this
latest change done and I've fixed it not to use -T. The compset -q and
faking $words[0] made me wonder that it wouldn't be a good idea to have
an option to compset to fake $words[0] as well. I think we do it in
quite a few other places.

Quoting Sven replying to me in 16752 (1st March):
> > Only I just wonder now: if we have to triplicate the list of commands
> > just to handle redirections (normal, < and >) it might end up being a
> > bit tedious.
> 
> I fear I don't understand this. We don't have to change anything
> unless we want to be able to offer new features (and if anything
> doesn't work this way it's a bug and I'd like to hear about it).

My worry was that if, for example in _gzip we wanted to handle all the
redirections we will need something like:

#compdef gzip gunzip gzcat -redirect->-gzip -redirect-<-gzip
-redirect-2>-gzip -redirect-<-gunzip -redirect->-gunzip
-redirect-2>gunzip -redirect-<-gzcat -redirect->-gzcat
-redirect-2>-gzcat -value-GZIP

so we either now use pattern completions a lot or allow
compdef {,-redirect-{<,>,2>}}-{gzip,gzcat,gunzip}

or have I misunderstood something somewhere?

also note that the above perhaps further backs up Bart's very good
point about keeping the redirection operator next to -redirect-.

Sven wrote:
> I forgot to say: somehow I think the way this is handled now is
> connected to the problem with default completions.  My thoughts are
> very fuzzy, though.

I've failed to spot the connection with default completions. Can you
summarise the issues perhaps?

On other points: a comma seems best as the separator though I'm not
particularly fussed. Quoting is probably the best solution to commands
with the separator in their name. Using a hyphen may be confusing
because it might cause problems if the trailing - of -redirect- can be
the separator as well as part of the context name.

Sven wrote:
> 
> That's ok, I think.  What do you suggest for values, then?
> `-value-<name>-<type>-<command>'?  <name> is the parameter name,
> <type> is scalar/array/... and <command> is only set when completing
> after something like `make FOO=<TAB>'.  That, by the way, is the
> reason why I put the command directly after the `-value-' or
> `-redirect-': it can be there in both cases.

Note that the old system allowed a completion function for a specific
association index though admittedly, we never used it.

By <type>, do you mean the full ${(t)name}? Useful I suppose but we're
going to get long contexts. This squashing everything we might want into
a string is starting to get silly.

Keeping the command always at the end is a good idea so that it is in a
consistent place (the beginning would be just as good).

It is also arguable that for normal completion, we should start with
something like -command-.

> > with the cursor positioned ON the `>', what context(s) get tried when I
> > press TAB?  I might expect it to complete file descriptor numbers ...
> > and in that case, I'd want to complete only the numbers of *valid* file
> > descriptors, but those aren't available to shell functions (yet).
> 
> Yes that would be nice.
> 
> Currently you should get argument completion (but strangely, trying
> `echo ><TAB>' shows that `-command-' is tried, only after `echo foo ><TBA>'
> do we get argument completion -- I'll have to have a look).

There are a few places where the division into contexts is not as ideal
as would be nice. Hence not being able to complete glob qualifiers,
parameter expansion flags etc as we do for subscript flags.

Oliver

#compdef -T values -P LC_* LANG

local locales

if (( $+commands[locale] )); then
  locales=( $(_call_program locales locale -a) )
else
  locales=( /usr/lib/locale/* )
fi

_wanted locales expl locale compadd "$@" -a locales -


This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.



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