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

Re: how to make zsh tab-complete path after colon (instead of just `=`)



On Tue, 2019-01-08 at 01:49 -0800, Timothee Cour wrote:
> is it possible make zsh complete filenames after a colon (instead of
> just after `=`) ?
> t foo=/tm<TAB> autocomples with /tmp
> t foo:/tm<TAB> doesn't do any autocomplete
> 
> (IIRC  in bash COMP_WORDBREAKS can be used for that)
> I don't want to specify this rule for every single command, I want it
> to apply to all commands by default

Generally speaking, zsh doesn't work like that --- it will perform
completion after colons in cases where that actually make sense, e.g. in
assignments to path variables etc.  So the right answer would indeed be
to make this happen in completions for the t command.

If you really want a brutal answer, however, it's not so hard to add a
style that will allow you to split all file completions on a given set
of characters.  The following simple patch allows you to set

zstyle ':completion:*' file-split-chars :

Given how brutal this is, I can well imagine there are cases this fails
horribly.  It is at least safe in the sense that if you don't set the
style nothing nasty will happen, and you have the usual style context
syntax to limit its application.  So it's probably about the best you're
likely to get.

pws

diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files
index 9fa6ae9..1021c34 100644
--- a/Completion/Unix/Type/_path_files
+++ b/Completion/Unix/Type/_path_files
@@ -2,6 +2,11 @@
 
 local -a match mbegin mend
 
+local splitchars
+if zstyle -s ":completion:${curcontext}:" file-split-chars splitchars; then
+  compset -P "*[${(q)splitchars}]"
+fi
+
 # Look for glob qualifiers.  Do this first:  if we're really
 # in a glob qualifier, we don't actually want to expand
 # the earlier part of the path.  We can't expand inside



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