zsh-users
 help / color / mirror / code / Atom feed
* how to make zsh tab-complete path after colon (instead of just `=`)
@ 2019-01-08  9:49 ` Timothee Cour
  2019-01-08 11:21   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Timothee Cour @ 2019-01-08  9:49 UTC (permalink / raw)
  To: Zsh Users

I have the same question as many others, see
https://stackoverflow.com/questions/40194030/make-zsh-tab-complete-path-after-colon
and https://unix.stackexchange.com/questions/445889/use-colon-as-filename-separator-in-zsh-tab-completion


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

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

* Re: how to make zsh tab-complete path after colon (instead of just `=`)
  2019-01-08  9:49 ` how to make zsh tab-complete path after colon (instead of just `=`) Timothee Cour
@ 2019-01-08 11:21   ` Peter Stephenson
  2019-01-08 12:37     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2019-01-08 11:21 UTC (permalink / raw)
  To: zsh-users

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


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

* Re: how to make zsh tab-complete path after colon (instead of just `=`)
  2019-01-08 11:21   ` Peter Stephenson
@ 2019-01-08 12:37     ` Peter Stephenson
  2019-01-08 15:32       ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2019-01-08 12:37 UTC (permalink / raw)
  To: zsh-users

On Tue, 2019-01-08 at 11:21 +0000, Peter Stephenson wrote:
> 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 :

I'm told this is probably good enough, and it's certainly not a big
change, and it's safe if you don't have the style set, so we might as
well get it in.  Someone may see some useful tweaks, e.g. it's quite
possible I haven't taken account of quoting properly.  Here's a full
patch with documentation.

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
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index a5a9e5b..3ce1c8c 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1568,6 +1568,16 @@ contains the string `tt(follow)', timestamps are associated with the
 targets of symbolic links; the default is to use the timestamps
 of the links themselves.
 )
+kindex(file-split-chars, completion style)
+item(tt(file-split-chars))(
+A set of characters that will cause em(all) file completions for
+the given context to be split at the point where any of the characters
+occurs.  A typical use is to set the style to tt(:); then everything
+up to and including the last tt(:) in the string so far is ignored when
+completing files.  As this is quite heavy-handed, it is usually
+preferable to update completion functions for contexts where this
+behaviour is useful.
+)
 kindex(filter, completion style)
 item(tt(filter))(
 The tt(ldap) plugin of email address completion (see tt(_email_addresses)) uses

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

* Re: how to make zsh tab-complete path after colon (instead of just `=`)
  2019-01-08 12:37     ` Peter Stephenson
@ 2019-01-08 15:32       ` Daniel Shahaf
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2019-01-08 15:32 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

Peter Stephenson wrote on Tue, Jan 08, 2019 at 12:37:31 +0000:
> I'm told this is probably good enough, and it's certainly not a big
> change, and it's safe if you don't have the style set, so we might as
> well get it in.

I'm not convinced we should.

The functionality provided is extremely specific (only file completion;
only single characters as the delimiter; etc).  It is also "brutal" (to
use your word), to the point that even the new documentation recommends
against using it.  Moreover, it could be implemented equivalently by
a short and equally brutal zshrc change (fewer than 10 lines), with
no changes to the completion standard library.

The new functionality does not make _path_files easier to maintain (it
adds four lines that everyone who changes this function from now one
will have to decipher) nor the manual easier to use (it reduces the
signal-to-noise ratio by adding a feature that self-describes as one
that shouldn't normally be used).

If we add and document this now, we'll be committed to supporting it for
eternity, and I am unsure that the added value justifies the cost.

I see you've pushed this already, so I would ask not to ship 5.7 with
this patch this week, in order to give time for discussion before the
backwards compatibility milk spills.

Cheers,

Daniel

> Someone may see some useful tweaks, e.g. it's quite possible I haven't
> taken account of quoting properly.  Here's a full patch with
> documentation.
> 
> 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
> diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
> index a5a9e5b..3ce1c8c 100644
> --- a/Doc/Zsh/compsys.yo
> +++ b/Doc/Zsh/compsys.yo
> @@ -1568,6 +1568,16 @@ contains the string `tt(follow)', timestamps are associated with the
>  targets of symbolic links; the default is to use the timestamps
>  of the links themselves.
>  )
> +kindex(file-split-chars, completion style)
> +item(tt(file-split-chars))(
> +A set of characters that will cause em(all) file completions for
> +the given context to be split at the point where any of the characters
> +occurs.  A typical use is to set the style to tt(:); then everything
> +up to and including the last tt(:) in the string so far is ignored when
> +completing files.  As this is quite heavy-handed, it is usually
> +preferable to update completion functions for contexts where this
> +behaviour is useful.
> +)
>  kindex(filter, completion style)
>  item(tt(filter))(
>  The tt(ldap) plugin of email address completion (see tt(_email_addresses)) uses

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

end of thread, other threads:[~2019-01-08 15:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20190108095220epcas2p1220c2b5ad3e9401282d243bcfea7ada1@epcas2p1.samsung.com>
2019-01-08  9:49 ` how to make zsh tab-complete path after colon (instead of just `=`) Timothee Cour
2019-01-08 11:21   ` Peter Stephenson
2019-01-08 12:37     ` Peter Stephenson
2019-01-08 15:32       ` Daniel Shahaf

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