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

Re: Use external tool if there are a large number of completions

On Sun, Sep 13, 2020 at 3:21 PM <gi1242+zsh@xxxxxxxxx> wrote:
> I was wondering if it's possible to use an external tool if there are
> more than a certain number of completions.

This is not directly possible for a few reasons.  For one, the strings
passed to the compadd builtin are allowed to be (and usually are)
potential rather than actual matches, which the completion internals
then filter down to the actual completions based on comparison to the
command line.   For another, once potential matches are collected via
compadd there is (at least at present) no way other than by that
comparison to remove non-matches from the set.

That said ... I can think of a possible way to do it.

Adopt a scheme similar to the one used by the _approximate completer,
which creates a function wrapper around the compadd builtin to
intercept the potential matches and apply corrections.  I'm not going
to attempt to write this, but the idea would be:  1) Build a wrapper
around compadd that interposes the "-A array" option (via "builtin
compadd") to collect the results in an array instead of adding them to
the internal data structures.  2) In a comppostfuncs function, remove
the wrapper and invoke your external command on the contents of that
array.  3) When you have the result of the external command, compadd
that as the single possible completion.

It will require some considerable care for this to interact correctly
with _approximate and _complete_help, if not some other completers.
It will also mess up things like groups and explanations.  You're
likely to be better off with Oliver's suggestion of the complist
module, or create a separate keybinding to delegate the entire process
to rofi and when you encounter the "do you wish to see all 3069
possibilities?" prompt, say no and type your rofi binding.

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