From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9953 invoked by alias); 29 Oct 2015 10:53:53 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20853 Received: (qmail 28966 invoked from network); 29 Oct 2015 10:53:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f794b6d000001495-5e-5631faba8aa3 Date: Thu, 29 Oct 2015 10:53:43 +0000 From: Peter Stephenson To: Zsh Users Subject: Re: Recursive globbing shorthand (a la **.c) Message-id: <20151029105343.67b579f3@pwslap01u.europe.root.pri> In-reply-to: <20151028065702.GA8236@linux.vnet.ibm.com> References: <20151028065702.GA8236@linux.vnet.ibm.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCLMWRmVeSWpSXmKPExsVy+t/xK7q7fhmGGWx8pWex4+RKRgdGj1UH PzAFMEZx2aSk5mSWpRbp2yVwZTz/9Ze94LZUxaw1vxgbGFtFuhg5OSQETCQet19kg7DFJC7c Ww9kc3EICSxllGh+vIgVwpnGJPF3519GCGcbo8Tv6XMZQVpYBFQl+nrOgrWzCRhKTN00Gywu IqAocebXNyYQW1jAVOLm4t9gNq+AvcSdjpmsIDangLnEii8NYLaQgJnEyfWvwWr4BfQlrv79 xARxkr3EzCtnGCF6BSV+TL7HAmIzC2hJbN7WxAphy0tsXvOWGWKOusSNu7vZJzAKzULSMgtJ yywkLQsYmVcxiqaWJhcUJ6XnGukVJ+YWl+al6yXn525ihITt1x2MS49ZHWIU4GBU4uFd2WIY JsSaWFZcmXuIUYKDWUmEV+gGUIg3JbGyKrUoP76oNCe1+BCjNAeLkjjvzF3vQ4QE0hNLUrNT UwtSi2CyTBycUg2M+ZH7V1ZOb8kt4Yh72GabbHJh3vKHi1fZlvyNv7FXfWYVN8t6Ruc3l/3+ 7eDYwV7T6O3edHNSkcNaXinbitvXTKe7T4gxEftWKLdx5p+lsV80tisEPuBUrL+4rDHVgOfi ZK5NcU1Lu9rqONbsOPTFJrdTvUz2y5tfC9ZbsC2NiDx8+mnLRaPdSizFGYmGWsxFxYkAY4d+ wlcCAAA= On Wed, 28 Oct 2015 07:57:02 +0100 Dominik Vogt wrote: > Most of the time, I use recursive globbing to find files of > certain types, e.g. > > $ ll **/*.c > > With the zsh here (4.3.17), recursive globbing works only > with a plain ** anyway (i.e. in "**x" and "x**" the ** works just > like a plain "*"). So, is it possible (or a useful future > feature) to make "**" imply a trailing "/*" if not with a trailing > pattern? Then we could type > > $ ll **.c It turns out this is pretty trivial to implement as an option which I've called GLOBSTARSHORT. No documentation yet. It's trivial enough that I doubt this would be problematic to include. pws diff --git a/Src/glob.c b/Src/glob.c index 24e60d0..51ffeb5 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -682,25 +682,32 @@ parsecomplist(char *instr) 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] == '/'))) { - /* Match any number of directories. */ - int follow; - - /* with three stars, follow symbolic links */ - follow = (instr[2] == Star); - instr += (3 + follow); - - /* Now get the next path component if there is one. */ - l1 = (Complist) zhalloc(sizeof *l1); - if ((l1->next = parsecomplist(instr)) == NULL) { - errflag |= ERRFLAG_ERROR; - return NULL; + if (instr[0] == Star && instr[1] == Star) { + int shortglob = 0; + if (instr[2] == '/' || (instr[2] == Star && instr[3] == '/') + || (shortglob = isset(GLOBSTARSHORT))) { + /* Match any number of directories. */ + int follow; + + /* with three stars, follow symbolic links */ + follow = (instr[2] == Star); + /* + * With GLOBSTARSHORT, leave a star in place for the + * pattern inside the directory. + */ + instr += ((shortglob ? 1 : 3) + follow); + + /* Now get the next path component if there is one. */ + l1 = (Complist) zhalloc(sizeof *l1); + if ((l1->next = parsecomplist(instr)) == NULL) { + errflag |= ERRFLAG_ERROR; + return NULL; + } + l1->pat = patcompile(NULL, compflags | PAT_ANY, NULL); + l1->closure = 1; /* ...zero or more times. */ + l1->follow = follow; + return l1; } - l1->pat = patcompile(NULL, compflags | PAT_ANY, NULL); - l1->closure = 1; /* ...zero or more times. */ - l1->follow = follow; - return l1; } /* Parse repeated directories such as (dir/)# and (dir/)## */ diff --git a/Src/options.c b/Src/options.c index 1fb102f..3bf9f39 100644 --- a/Src/options.c +++ b/Src/options.c @@ -140,6 +140,7 @@ static struct optname optns[] = { {{NULL, "globassign", OPT_EMULATE|OPT_CSH}, GLOBASSIGN}, {{NULL, "globcomplete", 0}, GLOBCOMPLETE}, {{NULL, "globdots", OPT_EMULATE}, GLOBDOTS}, +{{NULL, "globstarshort", OPT_EMULATE}, GLOBSTARSHORT}, {{NULL, "globsubst", OPT_EMULATE|OPT_NONZSH}, GLOBSUBST}, {{NULL, "hashcmds", OPT_ALL}, HASHCMDS}, {{NULL, "hashdirs", OPT_ALL}, HASHDIRS}, diff --git a/Src/zsh.h b/Src/zsh.h index f819249..a600105 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2218,6 +2218,7 @@ enum { GLOBASSIGN, GLOBCOMPLETE, GLOBDOTS, + GLOBSTARSHORT, GLOBSUBST, HASHCMDS, HASHDIRS,