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

Re: [BUG] incorrect expansion with expand-or-complete and single quote



On Fri, Jun 20, 2025 at 5:56 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Thu, Jun 19, 2025 at 6:13 PM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> >
> > I recall the following bug I posted in workers/53040 (with a
> > small correction in workers/53041) concerning expansion with
> > expand-or-complete and single quote.
> >
> > Nothing has changed in 5.9.0.2-test.
>
> Single quotes have always been a problem for compsys, because the
> low-level code that implements comparisons has to preserve
> tokenization of the quoted parts of the word from the command line
> while also un-tokenizing the parts that should be interpreted as
> patterns, then rebuild the whole thing in a form that can be passed to
> the shell-level functions that actually do the work, and then reverse
> all this again after compadd before putting the results back on the
> command line or into a completion list.
>
> It does this in part by converting the word from whatever quoting
> actually appears on the command line to use a consistent form
> throughout, but that means some details are lost.  This turns out to
> be worst when single quotes are protected by backslashes instead of
> being enclosed in double-quotes.
>
> I don't think this can be fixed purely at the current shell code
> level, and fixing it in the C code deep and early in the compsys flow
> is not only difficult but would likely force cascading changes through
> many of the existing shell functions.  File names and other words
> containing single quotes are just not a very common completion case,
> and unless we get a volunteer to develop a Sven W. depth of
> understanding of the completion internals, are likely to remain a
> broken case.

For what it's worth, this case works for me with the compsys stuff
loaded (eg, when I press tab with my setup), but in zsh -f (or by
using the expand-word widget directly), it does break in the way
Vincent described. Using list-choices followed by all-matches[1] also
works for both cases described, in case that's a satisfactory
workaround.

[1]
zstyle ':completion:all-matches:*' old-matches only
zstyle ':completion:all-matches::::' completer _all_matches
zle -C all-matches complete-word _generic

-- 
Mikael Magnusson




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