zsh-workers
 help / color / mirror / code / Atom feed
* Use external tool if there are a large number of completions
@ 2020-09-13 22:21 gi1242+zsh
  2020-09-14  0:14 ` Daniel Shahaf
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: gi1242+zsh @ 2020-09-13 22:21 UTC (permalink / raw)
  To: zsh-workers

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use external tool if there are a large number of completions
  2020-09-13 22:21 Use external tool if there are a large number of completions gi1242+zsh
@ 2020-09-14  0:14 ` Daniel Shahaf
  2020-09-14 12:29 ` Oliver Kiddle
  2020-09-14 20:32 ` Bart Schaefer
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2020-09-14  0:14 UTC (permalink / raw)
  To: gi1242+zsh; +Cc: zsh-workers

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use external tool if there are a large number of completions
  2020-09-13 22:21 Use external tool if there are a large number of completions gi1242+zsh
  2020-09-14  0:14 ` Daniel Shahaf
@ 2020-09-14 12:29 ` Oliver Kiddle
  2020-09-14 20:32 ` Bart Schaefer
  2 siblings, 0 replies; 5+ messages in thread
From: Oliver Kiddle @ 2020-09-14 12:29 UTC (permalink / raw)
  To: gi1242+zsh, zsh-workers

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use external tool if there are a large number of completions
  2020-09-13 22:21 Use external tool if there are a large number of completions gi1242+zsh
  2020-09-14  0:14 ` Daniel Shahaf
  2020-09-14 12:29 ` Oliver Kiddle
@ 2020-09-14 20:32 ` Bart Schaefer
  2020-09-15  1:16   ` gi1242+zsh
  2 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2020-09-14 20:32 UTC (permalink / raw)
  To: gi1242+zsh, zsh-workers

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use external tool if there are a large number of completions
  2020-09-14 20:32 ` Bart Schaefer
@ 2020-09-15  1:16   ` gi1242+zsh
  0 siblings, 0 replies; 5+ messages in thread
From: gi1242+zsh @ 2020-09-15  1:16 UTC (permalink / raw)
  To: zsh-workers

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-15  1:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-13 22:21 Use external tool if there are a large number of completions gi1242+zsh
2020-09-14  0:14 ` Daniel Shahaf
2020-09-14 12:29 ` Oliver Kiddle
2020-09-14 20:32 ` Bart Schaefer
2020-09-15  1:16   ` gi1242+zsh

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).