zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: <zsh-workers@zsh.org>
Subject: Re: When GLOB_COMPLETE is on, tab completion does not work with path containing hyphens
Date: Mon, 9 Dec 2019 10:34:51 +0000	[thread overview]
Message-ID: <1575887691.4486.6.camel@samsung.com> (raw)
In-Reply-To: <1575886903.4486.4.camel@samsung.com>

On Mon, 2019-12-09 at 10:21 +0000, Peter Stephenson wrote:
> +    for (ccount = 0, psrc = s, pdst = lpre;
> +	 ccount < lpl;
> +	 ++ccount, ++psrc, ++pdst)
> +    {
> +	if (*psrc == Dash)
> +	    *pdst = '-';
> +	else
> +	    *pdst = *psrc;
> +    }

This is a bit better thought through --- check if globbing is actually
in use and also beware of metafied characters.

pws

diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index f242e1b28..1dcec387d 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -3178,7 +3178,27 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd)
     /* Compute line prefix/suffix. */
     lpl = offs;
     lpre = zhalloc(lpl + 1);
-    memcpy(lpre, s, lpl);
+    if (comppatmatch)
+    {
+	int ccount;
+	char *psrc, *pdst;
+	for (ccount = 0, psrc = s, pdst = lpre;
+	     ccount < lpl;
+	     ++ccount, ++psrc, ++pdst)
+	{
+	    if (*psrc == Meta)
+	    {
+		ccount++;
+		*pdst++ = *psrc++;
+		*pdst = *psrc;
+	    } else if (*psrc == Dash)
+		*pdst = '-';
+	    else
+		*pdst = *psrc;
+	}
+    }
+    else
+	memcpy(lpre, s, lpl);
     lpre[lpl] = '\0';
     qlpre = quotename(lpre);
     lsuf = dupstring(s + offs);



  reply	other threads:[~2019-12-09 10:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-09  1:19 Felix.Chen
2019-12-09  9:23 ` Mikael Magnusson
2019-12-09  9:29   ` Daniel Shahaf
2019-12-09 10:21     ` Peter Stephenson
2019-12-09 10:34       ` Peter Stephenson [this message]
2019-12-10  0:51   ` Felix Chen

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=1575887691.4486.6.camel@samsung.com \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@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).