Hi All, I was wondering if it's possible to use an external tool if there are more than a certain number of completions. Sometimes there are thousands of completions (eg apt install), and the keyboard interface isn't too efficient. However, things like "rofi" handle this very nicely. So is it possible to invoke a custom command (e.g. rofi -dmenu) if there is more than (say) half a screenful of completions? Thanks, GI -- Experience is what a comb gives you after you lose your hair.
gi1242+zsh@gmail.com wrote on Sun, 13 Sep 2020 18:21 -0400: > I was wondering if it's possible to use an external tool if there are > more than a certain number of completions. Sometimes there are thousands > of completions (eg apt install), and the keyboard interface isn't too > efficient. However, things like "rofi" handle this very nicely. So is it > possible to invoke a custom command (e.g. rofi -dmenu) if there is more > than (say) half a screenful of completions? [ For context, rofi(1) is a GUI tool for selecting one text line out of a list. ] You might be able to engineer something using «compadd -O». There's also <https://github.com/Valodim/zsh-capture-completion>, though I haven't used it myself.
gi1242+zsh@gmail.com wrote:
> I was wondering if it's possible to use an external tool if there are
> more than a certain number of completions. Sometimes there are thousands
> of completions (eg apt install), and the keyboard interface isn't too
> efficient. However, things like "rofi" handle this very nicely. So is it
> possible to invoke a custom command (e.g. rofi -dmenu) if there is more
> than (say) half a screenful of completions?
Have you enabled and configured the complist module. It has some
similarities to tools such as rofi in that it can immediately present a
screenful of completion matches and allow one to be selected. They keys
are configurable and I find them to be fairly efficient.
Oliver
On Sun, Sep 13, 2020 at 3:21 PM <gi1242+zsh@gmail.com> 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.
On Mon, Sep 14, 2020 at 01:32:35PM -0700, Bart Schaefer wrote:
> 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.
Hi All,
Thanks a lot for the quick replies. Looks like this is what I'll do --
create a separate binding, and call it when there are too many matches.
GI
--
'Confidence' -- The feeling a person has before he fully understands the
situation.