zsh-users
 help / color / mirror / code / Atom feed
* completion ( compctl ) does not trigger for command names containing dashes
@ 2023-05-03  9:59 Fredrik Ax
  2023-05-03 17:13 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Fredrik Ax @ 2023-05-03  9:59 UTC (permalink / raw)
  To: zsh-users, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]

What I'm running:

% cat /etc/debian_version
12.0

% dpkg -l zsh | grep ii
ii  zsh            5.9-4        amd64        shell with lots of features

Hi,

I've used zsh compctl since forever (late 90s or early 00s) but strangely
never run into this before. I realized today when I intended to make some
compctl config for update-alternatives that my completions where not
triggered at all, it just used my standard fallback completion (files) ...
so a very stripped down simple example to show the problem:

This works fine:
~~~

zshprompt% compctl -k '(arg1 arg2 arg3)' nodash

# typing 'nodash ' and hitting [Tab] once:
zshprompt% nodash arg

# hitting [Tab again]
zshprompt% nodash arg
arg1 arg2 arg3

~~~

But this complete files instead:
~~~

# just showing the current dir for reference:
zshprompt% ls .
file2.txt  myfile1.txt

zshprompt% compctl -k '(arg1 arg2 arg3)' with-dash

# typing 'with-dash ' and hitting [Tab] once:
zshprompt% with-dash
file2.txt    myfile1.txt

~~~

As seen, my standard completion (listing current directory) is used rather
than the one I added with compctl ... I also tried this with a totally
clean zsh (no distribution or user configuration) and that shows the same
problem, commands without dashes triggers completion, but commands with
dashes, does not.

I couldn't really find anything about this in the manpage (man zshcompctl)
or online ...

Is it a bug, or am I missing something?

TIA,

/frax

[-- Attachment #2: Type: text/html, Size: 3260 bytes --]

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

* Re: completion ( compctl ) does not trigger for command names containing dashes
  2023-05-03  9:59 completion ( compctl ) does not trigger for command names containing dashes Fredrik Ax
@ 2023-05-03 17:13 ` Bart Schaefer
  2023-05-04  7:52   ` Fredrik Ax
  2023-05-04 10:36   ` Fredrik Ax
  0 siblings, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 2023-05-03 17:13 UTC (permalink / raw)
  To: Fredrik Ax; +Cc: zsh-users, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 537 bytes --]

On Wed, May 3, 2023 at 2:59 AM Fredrik Ax <fredrik@axnet.nu> wrote:
>
> zshprompt% compctl -k '(arg1 arg2 arg3)' with-dash
>
> # typing 'with-dash ' and hitting [Tab] once:
> zshprompt% with-dash
> file2.txt    myfile1.txt

This dates back to the tokenization of hyphens to fix bugs in [a-z]
types of patterns.  The ancient code in compctl is using the raw
command string and therefore looking for completions for
$'with\233-dash' rather than 'with-dash'.

See if this (attached) fixes it without breaking anything else.

[-- Attachment #2: compctl-dash.txt --]
[-- Type: text/plain, Size: 452 bytes --]

diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index 690cf6efb..6ceb5d87f 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -1315,6 +1315,8 @@ get_comp_string(void)
 	    ins = (tok == REPEAT ? 2 : (tok != STRING && tok != TYPESET));
 	    zsfree(cmdstr);
 	    cmdstr = ztrdup(tokstr);
+	    untokenize(cmdstr);
+	    remnulargs(cmdstr);
 	    cmdtok = tok;
 	    /*
 	     * If everything before is a redirection, or anything

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

* Re: completion ( compctl ) does not trigger for command names containing dashes
  2023-05-03 17:13 ` Bart Schaefer
@ 2023-05-04  7:52   ` Fredrik Ax
  2023-05-04 10:36   ` Fredrik Ax
  1 sibling, 0 replies; 6+ messages in thread
From: Fredrik Ax @ 2023-05-04  7:52 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Fredrik Ax, zsh-users, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]

thx I'll give it a shoot

Den ons 3 maj 2023 kl 19:13 skrev Bart Schaefer <schaefer@brasslantern.com>:

> On Wed, May 3, 2023 at 2:59 AM Fredrik Ax <fredrik@axnet.nu> wrote:
> >
> > zshprompt% compctl -k '(arg1 arg2 arg3)' with-dash
> >
> > # typing 'with-dash ' and hitting [Tab] once:
> > zshprompt% with-dash
> > file2.txt    myfile1.txt
>
> This dates back to the tokenization of hyphens to fix bugs in [a-z]
> types of patterns.  The ancient code in compctl is using the raw
> command string and therefore looking for completions for
> $'with\233-dash' rather than 'with-dash'.
>
> See if this (attached) fixes it without breaking anything else.
>

[-- Attachment #2: Type: text/html, Size: 1103 bytes --]

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

* Re: completion ( compctl ) does not trigger for command names containing dashes
  2023-05-03 17:13 ` Bart Schaefer
  2023-05-04  7:52   ` Fredrik Ax
@ 2023-05-04 10:36   ` Fredrik Ax
  2023-05-04 14:44     ` Bart Schaefer
  1 sibling, 1 reply; 6+ messages in thread
From: Fredrik Ax @ 2023-05-04 10:36 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Fredrik Ax, zsh-users, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1243 bytes --]

> Den ons 3 maj 2023 kl 19:13 skrev Bart Schaefer <schaefer@brasslantern.com
>:
>
> On Wed, May 3, 2023 at 2:59 AM Fredrik Ax <fredrik@axnet.nu> wrote:
> >
> > zshprompt% compctl -k '(arg1 arg2 arg3)' with-dash
> >
> > # typing 'with-dash ' and hitting [Tab] once:
> > zshprompt% with-dash
> > file2.txt    myfile1.txt
>
> This dates back to the tokenization of hyphens to fix bugs in [a-z]
> types of patterns.  The ancient code in compctl is using the raw
> command string and therefore looking for completions for
> $'with\233-dash' rather than 'with-dash'.
>
>  See if this (attached) fixes it without breaking anything else.

Thanks!

I made a quilt patch of this for the debian zsh_5.9-4 source package,
rebuilt and installed it ... it seems to be working fine. No build or
install issues, commands-with-dashes-in-the-name are now matched by the
compctl rules ... looking good.

Will keep running it for a while to see if I get anything else breaking by
it.
Can you give some pointers of which areas might get affected by this
change, what to look for?

Once, I'm satisfied it works well without breaking other stuff, how do I
best submit this for upstream inclusion?

Again, thanks in advance
/frax

[-- Attachment #2: Type: text/html, Size: 2172 bytes --]

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

* Re: completion ( compctl ) does not trigger for command names containing dashes
  2023-05-04 10:36   ` Fredrik Ax
@ 2023-05-04 14:44     ` Bart Schaefer
  2023-05-07  9:41       ` Fredrik Ax
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2023-05-04 14:44 UTC (permalink / raw)
  To: Fredrik Ax; +Cc: zsh-users

On Thu, May 4, 2023 at 3:36 AM Fredrik Ax <fredrik@axnet.nu> wrote:
>
> Can you give some pointers of which areas might get affected by this change, what to look for?

It changes one of the values returned from the line editor to the
completion code when examining the contents of the command line, but I
believe that particular value is never used outside compctl
completions.

> Once, I'm satisfied it works well without breaking other stuff, how do I best submit this for upstream inclusion?

Unless you find a problem with it, I'll take care of including it.


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

* Re: completion ( compctl ) does not trigger for command names containing dashes
  2023-05-04 14:44     ` Bart Schaefer
@ 2023-05-07  9:41       ` Fredrik Ax
  0 siblings, 0 replies; 6+ messages in thread
From: Fredrik Ax @ 2023-05-07  9:41 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Fredrik Ax, zsh-users

[-- Attachment #1: Type: text/plain, Size: 856 bytes --]

Great, thanks!

I've used it for a couple of days without any problem now. I don't (in any
way) mind you including it, thanks.

Again, thank you Bart!
/frax

Den tors 4 maj 2023 kl 16:45 skrev Bart Schaefer <schaefer@brasslantern.com
>:

> On Thu, May 4, 2023 at 3:36 AM Fredrik Ax <fredrik@axnet.nu> wrote:
> >
> > Can you give some pointers of which areas might get affected by this
> change, what to look for?
>
> It changes one of the values returned from the line editor to the
> completion code when examining the contents of the command line, but I
> believe that particular value is never used outside compctl
> completions.
>
> > Once, I'm satisfied it works well without breaking other stuff, how do I
> best submit this for upstream inclusion?
>
> Unless you find a problem with it, I'll take care of including it.
>

[-- Attachment #2: Type: text/html, Size: 1281 bytes --]

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

end of thread, other threads:[~2023-05-07  9:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03  9:59 completion ( compctl ) does not trigger for command names containing dashes Fredrik Ax
2023-05-03 17:13 ` Bart Schaefer
2023-05-04  7:52   ` Fredrik Ax
2023-05-04 10:36   ` Fredrik Ax
2023-05-04 14:44     ` Bart Schaefer
2023-05-07  9:41       ` Fredrik Ax

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