zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Tomasz Pala <gotar@polanet.pl>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: _complete: insert unambiguous when globbing
Date: Mon, 3 Jan 2022 16:25:18 -0800	[thread overview]
Message-ID: <CAH+w=7YobgajzubM-nhbr39cHUn=WcaKMG4oXRkZiorWgdvbjg@mail.gmail.com> (raw)
In-Reply-To: <20220103123903.GA20434@polanet.pl>

On Mon, Jan 3, 2022 at 7:24 AM Tomasz Pala <gotar@polanet.pl> wrote:
>
> ls 2[tab]       ==> 20          this is expected
> ls 2*[tab]      !=> 20          how to make this to be expanded first to
>
> "20", and then the regular rules to proceed (either menu complete I
> always use, or _expand)?

The basic problem here is that the set of common prefixes always
includes the string originally on the command line when deciding
whether to insert a partial result, and except in pretty unusual cases
none of the results is going to include the "*" character, so the best
you're going to get is to always immediately enter menu completion.
You can get that with

setopt globcomplete

This varies a bit depending on your key bindings and completer style.
The above is required when you have TAB bound to expand-or-complete,
but for example with

bindkey ^I complete-word
zstyle ':completion:*' completer _complete _expand

you can get a similar set of results, but menu completion is entered
with all possible expansions instead of all matching files.

> One more note - zsh knows where the first ambiguous character is, even
> with globbing, as it's shown with show-ambiguity style.

Hmm.  When I try this with your 20{a,b,c,d}.x example, globcomplete
gives "20" as the unambiguous prefix but my second formulation has
only "2".  This appears to be because with globcomplete on, the set of
glob matches has already been calculated before entering the
completion process; the prefix from the command line is determined
very early in both cases.  This suggests that some fiddling with the
value of compstate[insert] could produce the "show prefix on first
tab, enter menu on second tab" effect that I think you're asking for,
at least some of the time, but I'm not sure where to do that.


  parent reply	other threads:[~2022-01-04  0:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 12:39 Tomasz Pala
2022-01-03 15:40 ` Tomasz Pala
2022-01-04  0:25 ` Bart Schaefer [this message]
2022-01-05 19:46   ` Tomasz Pala
2022-01-05 20:11     ` Bart Schaefer
2022-01-06  1:52       ` Tomasz Pala
2022-01-06 10:38         ` Tomasz Pala
2022-01-05 20:15     ` Tomasz Pala
2022-01-05 20:25       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7YobgajzubM-nhbr39cHUn=WcaKMG4oXRkZiorWgdvbjg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=gotar@polanet.pl \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).