zsh-users
 help / color / mirror / code / Atom feed
* How to have Zsh completion menu and use glob patterns + recursive search?
@ 2023-06-29 12:40 Marc Coquand
  2023-06-30  0:44 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Coquand @ 2023-06-29 12:40 UTC (permalink / raw)
  To: zsh-users

I have the following setup for zsh completion

autoload -U compinit && compinit

zstyle ':completion:*' menu select
zstyle ':completion:*' complete-options true

setopt GLOB_COMPLETE
zstyle ':completion*:default' menu 'select=0'
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zmodload zsh/complist

Which gives me a nice autocomplete menu when I tab, where I can switch between different options. However, I'd like to be able to do ./**/*file*<tab> and get a selectable list of all options available.

I notice that if I remove all the previous options that I have enabled, ./**/*file*<tab> works but it expands to all available options. I'd like to have it instead as a menu of options that I can tab between. However, if I enable the completion list, ./**/*file*<tab> stops working and doesn't do anything.

So how do I enable so that I can recursively search for a file and have it show up in an auto-completion menu that I can tab between?


Thank you so much for your help
Marc



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

* Re: How to have Zsh completion menu and use glob patterns + recursive search?
  2023-06-29 12:40 How to have Zsh completion menu and use glob patterns + recursive search? Marc Coquand
@ 2023-06-30  0:44 ` Bart Schaefer
  2023-06-30  7:19   ` Marc Coquand
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2023-06-30  0:44 UTC (permalink / raw)
  To: Marc Coquand; +Cc: zsh-users

On Thu, Jun 29, 2023 at 5:40 AM Marc Coquand <marcc0000@pm.me> wrote:
>
> I'd like to be able to do ./**/*file*<tab> and get a selectable list of all options available.

"do" that where?  Usually it would be after a command word such as
"ls" or "vi".  Each command may have a different completion function
that supplies contextual clues to adjust the results.

Presuming we're just talking about generic file completion context:

> I notice that if I remove all the previous options that I have enabled, ./**/*file*<tab> works but it expands to all available options.

That's because the default binding for the tab key is
"expand-or-complete".  You're seeing the results of the "expand" part,
which takes place before completion is attempted.  In many cases after
"compinit" you want to change the binding of tab to be
"complete-word".

bindkey $'\t' complete-word

> However, if I enable the completion list, ./**/*file*<tab> stops working and doesn't do anything.

You need the bindkey above (see the documention for _expand), followed
by at the least (other completer entries are possible)

zstyle ':completion:*' completer _expand _complete

The _expand completer takes the place of the expansion part of
"expand-or-complete" and (in effect) feeds the expansions back to the
completion menu instead of populating the command line directly.

You probably also want

zstyle :completion::expand::: tag-order expansions original

otherwise _expand will offer "all-expansions", that is, the "all
available options" set you didn't like, as one of the possible menu
choices, which if it is a large listing can have unexpected
side-effects on the display.


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

* Re: How to have Zsh completion menu and use glob patterns + recursive search?
  2023-06-30  0:44 ` Bart Schaefer
@ 2023-06-30  7:19   ` Marc Coquand
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Coquand @ 2023-06-30  7:19 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Hey,

You are correct in assuming it's just generic file completion. I tried
your recommendation and now it works exactly how I want it. Thank you
so much! :) 

Sincerely,
Marc

On Fri Jun 30, 2023 at 2:44 AM CEST, Bart Schaefer wrote:
> On Thu, Jun 29, 2023 at 5:40 AM Marc Coquand <marcc0000@pm.me> wrote:
> >
> > I'd like to be able to do ./**/*file*<tab> and get a selectable list of all options available.
>
> "do" that where?  Usually it would be after a command word such as
> "ls" or "vi".  Each command may have a different completion function
> that supplies contextual clues to adjust the results.
>
> Presuming we're just talking about generic file completion context:
>
> > I notice that if I remove all the previous options that I have enabled, ./**/*file*<tab> works but it expands to all available options.
>
> That's because the default binding for the tab key is
> "expand-or-complete".  You're seeing the results of the "expand" part,
> which takes place before completion is attempted.  In many cases after
> "compinit" you want to change the binding of tab to be
> "complete-word".
>
> bindkey $'\t' complete-word
>
> > However, if I enable the completion list, ./**/*file*<tab> stops working and doesn't do anything.
>
> You need the bindkey above (see the documention for _expand), followed
> by at the least (other completer entries are possible)
>
> zstyle ':completion:*' completer _expand _complete
>
> The _expand completer takes the place of the expansion part of
> "expand-or-complete" and (in effect) feeds the expansions back to the
> completion menu instead of populating the command line directly.
>
> You probably also want
>
> zstyle :completion::expand::: tag-order expansions original
>
> otherwise _expand will offer "all-expansions", that is, the "all
> available options" set you didn't like, as one of the possible menu
> choices, which if it is a large listing can have unexpected
> side-effects on the display.




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

end of thread, other threads:[~2023-06-30  7:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-29 12:40 How to have Zsh completion menu and use glob patterns + recursive search? Marc Coquand
2023-06-30  0:44 ` Bart Schaefer
2023-06-30  7:19   ` Marc Coquand

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).