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

Re: GLOB_COMPLETE and numbered directories

On Mar 19,  9:06am, Bart Schaefer wrote:
} It's supposed to be sufficient to "setopt completeinword" to get the
} behavior you want, and indeed it works if I literally type out
} % cat 1a/iota
} and then move the cursor to 1<C>a/iota before pressing TAB.  However,
} for some reason this doesn't happen when "continuing an in-progress
} completion" with a second TAB.  I believe that's because the second
} tab just regenerates the listing with the same pattern as on the
} first tab, and that's not sufficient to disambiguate.

So ... in the case of moving the cursor to after the "1" and pressing
TAB, $PREFIX = "1".  But in the case of pressing the second TAB after
completing to "1a/iota", $PREFIX = "1a/iota" even though the cursor
is not at the end of the word.

The fix is therefore something like this, though I don't know if I have
handled completeinword correctly (as in, I think this generates matches
on a second TAB even when completeinword is not set, but I don't think
anyone would object to that?).

diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
index d6a1007..a89bc84 100644
--- a/Completion/Base/Core/_main_complete
+++ b/Completion/Base/Core/_main_complete
@@ -68,6 +68,15 @@ if [[ "$compstate[insert]" = tab* ]]; then
   compstate[insert]="${compstate[insert]//tab /}"
+# Second attempt at GLOB_COMPLETE
+if [[ "$compstate[pattern_match]" = "*" &&
+      "$_lastcomp[unambiguous]" = "$PREFIX" &&
+      -n "$_lastcomp[unambiguous_cursor]" ]]; then
+  integer upos="$_lastcomp[unambiguous_cursor]"
+  PREFIX="$PREFIX[1,upos-1]*$PREFIX[upos,-1]"
 # Special completion contexts after `~' and `='.
 if [[ -z "$compstate[quote]" ]]; then

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