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

Re: _complete: insert unambiguous when globbing



On Mon, Jan 03, 2022 at 16:25:18 -0800, Bart Schaefer wrote:

> 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,

Can I get rid of this "original" string from the set? When backing of
from completion I always use ctrl-g anyway.

> 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,

Yes, something like this - this might happen on one or two tabs or even
on some separate keybinding.


I did some digging and I think I've found a solution for my usecase:


--- /usr/share/zsh/5.8/functions/_main_complete.orig    2020-02-19 00:50:21.000000000 +0100
+++ /usr/share/zsh/5.8/functions/_main_complete    2022-01-05 18:34:57.828262149 +0100
@@ -389,6 +389,12 @@
     unset ZLS_COLORS
   fi
 }
+
+if [[ $PREFIX = *'*'* ]]; then
+    compstate[pattern_insert]=not_menu
+else
+    compstate[old_list]=keep
+fi

 # Now call the post-functions.
===

However since it sacrifices ZLE-provided pattern it's not perfect.

$ cd empty
$ touch 2021.12.29-14:41:02.xz 2021.12.29-19:41:02.xz 2021.12.30-03:41:03.xz 2021.12.30-14:41:04.xz 2021.12.30-19:41:02.xz 2021.12.31-03:41:02.xz 2021.12.31-14:41:04.xz 2021.12.31-19:41:03.xz

$ ls 2*04[tab]	=> 2021.12.3
files
2021.12.30-14:41:04.xz  2021.12.31-14:41:04.xz

so the compstate[old_list]=keep was required for the second [tab] not to
follow the updated ZLE contents. It works like a charm, but I wonder -
what cases would be broken by compstate[old_list]=keep with such a weak
condition? It would be much safer to have something like:

if [[ $PREFIX = *'*'* ]]; then
	compstate[pattern_insert]=not_menu
	compstate[eat_globbing]=yes
elif [ "$compstate[eat_globbing]" = 'true' ]; then
	compstate[old_list]=keep
fi

but I can't find a way to pass this down.

-- 
Tomasz Pala <gotar@xxxxxxxxxxxxx>




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