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

Re: zmv exits from function



> On 02/01/2024 17:08 GMT Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> 
>  
> On 2024-01-02 03:50, Peter Stephenson wrote:
> >> On 30/12/2023 20:38 GMT Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >> Arguably zmv could use null_glob.  Thoughts from -workers?
> > I guess the right thing to do regardless of option is that it should
> > fail gracefully just by returning status 1 --- so not propagating the
> > error to the caller.
> 
> That's just was I was trying to say :-)

So how about this...

pws

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index f43ac2257..182fc5f0a 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -4667,11 +4667,12 @@ 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.
+whose name is not changed by the substitution is simply ignored; if no
+files are matched by the pattern, the function silently returns status
+1.  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..177428f08 100644
--- a/Functions/Misc/zmv
+++ b/Functions/Misc/zmv
@@ -236,7 +236,11 @@ if [[ $pat = (#b)(*)\((\*\*##/)\)(*) ]]; then
 else
   fpat=$pat
 fi
-files=(${~fpat})
+files=(${~fpat}(#qN))
+
+if (( ${#files} == 0 )); then
+  return 1
+fi
 
 [[ -n $hasglobqual ]] && pat=$opat




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