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

Re: Recursive globbing



Vincent Lefevre wrote:
> Hi,
> 
> Is there any difference between *.tex and **.tex ?

No, and in fact they are documented to be the same.  Hence...

> If there's none,
> how about having improved recursive globbing, where ** not followed
> by a slash would mean **/* (ditto for *** -> ***/*)?

I can't see any problem with this, unless people are habitually using
double stars in the place of single stars, for example to avoid having
to prune patterns.  I doubt it, but are they?

Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.33
diff -u -r1.33 glob.c
--- Src/glob.c	6 Apr 2004 17:45:47 -0000	1.33
+++ Src/glob.c	14 May 2004 10:50:20 -0000
@@ -639,14 +639,21 @@
     char *str;
     int compflags = gf_noglobdots ? (PAT_FILE|PAT_NOGLD) : PAT_FILE;
 
-    if (instr[0] == Star && instr[1] == Star &&
-        (instr[2] == '/' || (instr[2] == Star && instr[3] == '/'))) {
+    if (instr[0] == Star && instr[1] == Star) {
 	/* Match any number of directories. */
 	int follow;
 
 	/* with three stars, follow symbolic links */
 	follow = (instr[2] == Star);
-	instr += (3 + follow);
+        if (instr[2] == '/' || (instr[2] == Star && instr[3] == '/')) {
+	    instr += (3 + follow);
+	} else {
+	    /*
+	     * Make **(|[^/\*]*) or ***(|[^/]) equivalent to
+	     * **[/]*(...) or ***[/]*(...), respectively.
+	     */
+	    instr += 1 + follow;
+	}
 
 	/* Now get the next path component if there is one. */
 	l1 = (Complist) zhalloc(sizeof *l1);
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.49
diff -u -r1.49 expn.yo
--- Doc/Zsh/expn.yo	6 Apr 2004 09:26:50 -0000	1.49
+++ Doc/Zsh/expn.yo	14 May 2004 10:50:21 -0000
@@ -1590,9 +1590,12 @@
 does a recursive directory search for files named `tt(bar)' (potentially
 including the file `tt(bar)' in the current directory).  This form does not
 follow symbolic links; the alternative form `tt(***/)' does, but is
-otherwise identical.  Neither of these can be combined with other forms of
-globbing within the same path segment; in that case, the `tt(*)'
-operators revert to their usual effect.
+otherwise identical.
+
+As a further shorthand, `tt(**)' or `tt(***)' followed by anything other
+than a `tt(/)' are treated the same way as `tt(**/*)' and `tt(***/*)',
+respectively.  Hence `tt(**.c)' is equivalent to `tt(**/*.c)' and so to
+`tt((*/)#*.c)'.
 subsect(Glob Qualifiers)
 cindex(globbing, qualifiers)
 cindex(qualifiers, globbing)

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



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