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

Exluded patterns and leading .'s



I decided, after five minutes wrangling with the shell wondering what
was wrong, that excluded patterns (using ~) should not treat leading
.'s specially.

What I ran across was something like this:

print ../**/*foo*~*bar*

i.e., starting from the parent directory, look for files with `foo'
in them, ignoring any with `bar' in.

Now, it is the case, and has always been, that the stuff after the
tilde does not treat /'s specially, i.e. having found, say,
../wibble/footloose_barmaid, this is just treated as an ordinary
pattern for the exclusion part.  (In fact, with ** defined as it is
it's hard to think of any better way of doing it, because you don't
know how many slashes are going to be in the result.)

Unfortunately, it is also the case that the value of globdots is
respected, so in this case, footloose_barmaid is not excluded as you
would expect.  I propose that leading dots not be treated specially in
the exclusion part.  The point is that if you matched a `.' in the
pre-~ part, whether explicitly (as here) or otherwise, it's
counterintuitive not at least to consider excluding it.  In other
words, no footloose_barmaid.

Hope that's clear (clear as a pint of Guiness, probably).

(Actually, since 2.4 something it's been possible to do

print ../**/(*foo*~*bar*)

where /'s in the excluded pattern _are_ special, but that wasn't what
I wanted here.  I probably thought about making this change when I
made that one, but couldn't think of a reason for it.  Now I can.)

The glob code need some comments... perhaps later.

*** Src/glob.c~	Wed May 31 05:10:15 1995
--- Src/glob.c	Mon Jun 12 17:06:58 1995
***************
*** 1323,1334 ****
  
  /**/
  int
! excluded(Comp c, char *eptr, int efst)
  {
      char *saves = pptr;
      int savei = first, ret;
  
!     first = efst;
      pptr = (PATHADDP(c) && pathpos) ? getfullpath(eptr) : eptr;
  
      ret = doesmatch(c->exclude);
--- 1323,1334 ----
  
  /**/
  int
! excluded(Comp c, char *eptr)
  {
      char *saves = pptr;
      int savei = first, ret;
  
!     first = 0;
      pptr = (PATHADDP(c) && pathpos) ? getfullpath(eptr) : eptr;
  
      ret = doesmatch(c->exclude);
***************
*** 1371,1377 ****
  	    savei = first;
  	    if (c->left || c->right)
  		if (!doesmatch(c->left) ||
! 		    (c->exclude && excluded(c, saves, savei)))
  		    if (c->right) {
  			pptr = saves;
  			first = savei;
--- 1371,1377 ----
  	    savei = first;
  	    if (c->left || c->right)
  		if (!doesmatch(c->left) ||
! 		    (c->exclude && excluded(c, saves)))
  		    if (c->right) {
  			pptr = saves;
  			first = savei;

-- 
Peter Stephenson <P.Stephenson@xxxxxxxxxxxxx>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.




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