zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: histsubstpattern in zmv
Date: Fri, 2 Jun 2023 09:40:19 +0100 (BST)	[thread overview]
Message-ID: <1452348325.5131636.1685695219291@mail.virginmedia.com> (raw)
In-Reply-To: <20230601183556.nl3zhv2kdxgj7x4d@chazelas.org>

On 01/06/2023 19:35 Stephane Chazelas <stephane@chazelas.org> wrote:
> The csh-style ${var:s/foo/bar} is often more legible and easy
> to cumulate than the Korn-style equivalent ${var/foo/bar}
>..
> But that needs set -o histsubstpattern and in zmv, emulate -LR
> zsh resets options.
> 
> Would it be possibe to enable it in zmv along with extendedglob
> which is already enabled there, or if not allow the user to enable it,
> or maybe even better introduced some :+s/pattern/repl/
> :-s/string/repl/ or :S/pattern/replacement/ so we can use both
> at the same time, like ${f:gs/***/3-stars/:gS/???/any-3-chars} ?

I can't see any good reason not to enable it.  The range of
likely cases where this would cause problems is rather limited ---
I'd probably instinctively quote pattern characters anyway.  But
if anyone thinks we should consider something more sophisticated
we can.

pws

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 96de5aa9b..60553210c 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -4618,12 +4618,16 @@ example(zmv '(*).lis' '$1.txt')
 renames `tt(foo.lis)' to `tt(foo.txt)', `tt(my.old.stuff.lis)' to
 `tt(my.old.stuff.txt)', and so on.
 
-The pattern is always treated as an tt(EXTENDED_GLOB) pattern.  Any file
-whose name is not changed by the substitution is simply ignored.  Any
-error (a substitution resulted in an empty string, two substitutions gave
-the same result, the destination was an existing regular file and tt(-f)
-was not given) causes the entire function to abort without doing
-anything.
+The pattern is always treated as an tt(EXTENDED_GLOB) pattern.
+Furthermore, the tt(HIST_SUBST_PATTERN) option is enabled in order
+to allow the use of patterns in history-style substituions, i.e.
+tt(${f:s/)var(pat)tt(/)var(rep)tt(/}).
+
+Any file whose name is not changed by the substitution is simply
+ignored.  Any error (a substitution resulted in an empty string, two
+substitutions gave the same result, the destination was an existing
+regular file and tt(-f) was not given) causes the entire function to
+abort without doing anything.
 
 In addition to pattern replacement, the variable tt($f) can be referred
 to in the second (replacement) argument.  This makes it possible to
diff --git a/Functions/Misc/zmv b/Functions/Misc/zmv
index 269fe5ba5..58b0327cb 100644
--- a/Functions/Misc/zmv
+++ b/Functions/Misc/zmv
@@ -123,7 +123,7 @@
 #   paranoiacs like the author will probably put them there anyway.
 
 emulate -RL zsh
-setopt extendedglob
+setopt extendedglob histsubstpattern
 
 local f g args match mbegin mend files action myname tmpf opt exec
 local opt_f opt_i opt_n opt_q opt_Q opt_s opt_M opt_C opt_L


  reply	other threads:[~2023-06-02  8:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 18:35 Stephane Chazelas
2023-06-02  8:40 ` Peter Stephenson [this message]
2023-06-02 10:18   ` Peter Stephenson
2023-06-02 15:09     ` Stephane Chazelas
2023-06-02 15:29       ` Stephane Chazelas
2023-06-04 18:32       ` Peter Stephenson
2023-06-08  6:57       ` Jun T

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1452348325.5131636.1685695219291@mail.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).