__fish_complete_list: strip "--foo=" prefix from replacing completions

Given a command line like

	foo --foo=bar=baz=qux\=argument

(the behavior is the same if '=' is substituted with ':').

fish completes arguments starting from the last unescaped separator, i.e.

	foo --foo=bar=baz=qux\=argument
			 ^
__fish_complete_list provides completions like

	printf %s\n (commandline -t)(printf %s\n choice1 choice2 ...)

This means that completions include the "--foo=bar=baz=" prefix.

This is wrong. This wasn't a problem until commit f9febba (Fix replacing
completions with a -foo prefix, 2024-12-14), because prior to that, replacing
completions would replace the entire token.
This made it too hard to writ ecompletions like

	complete -c foo -s s -l long -xa "hello-world goodbye-friend"

that would work with "foo --long fri" as well as "foo --long=frie".
Replacing the entire token would only work if the completion included that
prefix, but the above command is supposed to just work.
So f9febba made us replace only the part after the separator.

Unfortunately that caused the earlier problem.  Work around this.  The change
is not pretty, but it's a compromise until we have a better way of telling
which character fish considers to be the separator.

Fixes #11508
This commit is contained in:
Johannes Altmanninger
2025-06-21 17:23:49 +02:00
parent ba00d721f4
commit 320ebb6859
24 changed files with 61 additions and 47 deletions

View File

@@ -635,3 +635,15 @@ complete -C'testcommand '
abbr cat cat
complete -C ca | string match -r '^cat(?:\t.*)?$'
# CHECK: cat{{\t}}Abbreviation: cat
complete complete-list -xa '(__fish_complete_list , "seq 2")'
complete -C "complete-list 1,"
# CHECK: 1,1
# CHECK: 1,2
complete complete-list -s l -l number-list -xa '(__fish_stripprefix="^(--number-list=|-\w*l)" __fish_complete_list , "seq 2")'
complete -C "complete-list --number-list=1,"
# CHECK: --number-list=1,1
# CHECK: --number-list=1,2
complete -C "complete-list -abcl1,"
# CHECK: -abcl1,1
# CHECK: -abcl1,2