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

Re: completion within a function

On 2020-12-29 1:48 p.m., Bart Schaefer wrote:

func ()
      cd $1 [TAB]

... so that I can automatically execute a completion within a function.
Where does the TAB come from?

That's what I'm asking.  How could I simulate the effect of completing on $1 within the function automatically?  Or perhaps:

    new_var=$( complete_it $1 )

where 'complete _it' is a function that does just what TAB would do on the command line.

I think what you're actually asking is how to apply the contextual
completion "rules" defined for a command ("cd" in this case) to a
parameter expansion.  There really is not any way to do that
"automatically" because completion is tightly bound to having the ZLE
line editor active.  It could be done the way that the test suite
emulates completion, but that's exceptionally convoluted, especially
error handling.
Geez, I'd have thought that it would just be a question of digging up the right completer.  But as you say.
'vared' is a variable editor no?  Does it do more than I think?
If you were to write

     vared 1
     cd $1

Then at the point vared is invoked, func would pause, wait for the
user to press TAB or whatever, and then after accept-line is executed,
continue with whatever result.
Cool.  That's bound to be useful even if not right now.  I had no idea it could be used within a function like that.


  local dirs=( $1*(-/N) )

Marvelous.  If I was 20 I'd devote the next 10 years to reading the manual and have the health to survive it.  The thing is that zsh code is so terse that you can't go searching for answers unless you already know where to look. Anyway, that line of yours does it all exactly as I want.  Thanks Bart.

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