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

Re: How to have Zsh completion menu and use glob patterns + recursive search?



On Thu, Jun 29, 2023 at 5:40 AM Marc Coquand <marcc0000@xxxxx> 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.




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