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

Re: Inconsistent behavior with comparisons and recursive glob patterns



(Moved from -users)

On Tue, Apr 30, 2024 at 11:15 AM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> I suspect there's no explicit reasoning in zmv.  **/ is specifically
> handled in the case of zmv -w/-W (workers/27247) but not for '$f'
> placeholders.
>
> It works if you do this:
>
> zmv -n '(**/)f?' '$f.txt'
>
> Whether it should also work without the parens and also without the -w
> option is unclear.

Attached patch makes it work without the parens.  Is this within spec?
 It's hard to tell from the solitary '$f' example in the doc.
diff --git a/Functions/Misc/zmv b/Functions/Misc/zmv
index 5c03e9ea1..2002af5a6 100644
--- a/Functions/Misc/zmv
+++ b/Functions/Misc/zmv
@@ -249,13 +249,13 @@ errs=()
 (( ${#files} )) || errs=( "no files matched \`$fpat'" )
 
 for f in $files; do
-  if [[ $pat = (#b)(*)\(\*\*##/\)(*) ]]; then
+  if [[ $pat = (#b)(*)(\(\*\*##/\)|\*\*##/)(*) ]]; then
     # This looks like a recursive glob.  This isn't good enough,
-    # because we should really enforce that $match[1] and $match[2]
+    # because we should really enforce that $match[1] and $match[3]
     # don't match slashes unless they were explicitly given.  But
     # it's a start.  It's fine for the classic case where (**/) is
     # at the start of the pattern.
-    pat="$match[1](*/|)$match[2]"
+    pat="$match[1](*/|)$match[3]"
   fi
   [[ -e $f && $f = (#b)${~pat} ]] || continue
   set -- "$match[@]"


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