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

PATCH: case-insensitive globbing



Michael Schaap wrote:
> It would be nice, though, if zsh had an option to make file globbing 
> case insensitive. I'd enable than on my Cygwin machine, since the 
> Windows file systems basically *are* case insensitive...
> 
> (Bash has such an option: nocaseglob...)

This has been on the wish list for ages, but I just realised it's
completely trivial to implement... so trivial it might as well be in
4.2.0.  It's just the existing code for (#i) turn on at the start
of all file globs.

(Follow-ups to zsh-workers, please, I just thought I'd advertise it...)

`setopt nocaseglob' (or `unsetopt caseglob') to activate.

Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.29
diff -u -r1.29 options.yo
--- Doc/Zsh/options.yo	10 Feb 2004 19:19:02 -0000	1.29
+++ Doc/Zsh/options.yo	6 Mar 2004 00:04:29 -0000
@@ -219,6 +219,16 @@
 This disables backslashed escape sequences in echo strings unless the
 tt(-e) option is specified.
 )
+pindex(CASE_GLOB)
+cindex(case-insensitive globbing, option)
+item(tt(CASE_GLOB) <D>)(
+Make globbing (filename generation) sensitive to case.  Note that other
+uses of patterns are always sensitive to case.  If the option is unset,
+the presence of any character which is special to filename generation
+will cause case-insensitive matching.  For example, tt(cvs(/)) can
+match the directory tt(CVS) owing to the presence of the globbing flag
+(unless the option tt(BARE_GLOB_QUAL) is unset).
+)
 pindex(C_BASES)
 cindex(bases, output in C format)
 cindex(hexadecimal, output in C format)
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.16
diff -u -r1.16 options.c
--- Src/options.c	15 May 2003 09:39:57 -0000	1.16
+++ Src/options.c	6 Mar 2004 00:04:38 -0000
@@ -92,6 +92,7 @@
 {NULL, "bgnice",	      OPT_EMULATE|OPT_NONBOURNE, BGNICE},
 {NULL, "braceccl",	      OPT_EMULATE,		 BRACECCL},
 {NULL, "bsdecho",	      OPT_EMULATE|OPT_SH,	 BSDECHO},
+{NULL, "caseglob",	      OPT_ALL,			 CASEGLOB},
 {NULL, "cbases",	      0,			 CBASES},
 {NULL, "cdablevars",	      OPT_EMULATE,		 CDABLEVARS},
 {NULL, "chasedots",	      OPT_EMULATE,		 CHASEDOTS},
Index: Src/pattern.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/pattern.c,v
retrieving revision 1.16
diff -u -r1.16 pattern.c
--- Src/pattern.c	3 Dec 2003 10:54:36 -0000	1.16
+++ Src/pattern.c	6 Mar 2004 00:04:46 -0000
@@ -289,7 +289,10 @@
 void
 patcompstart(void)
 {
-    patglobflags = 0;
+    if (isset(CASEGLOB))
+	patglobflags = 0;
+    else
+	patglobflags = GF_IGNCASE;
 }
 
 /* Top level pattern compilation subroutine */
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.52
diff -u -r1.52 zsh.h
--- Src/zsh.h	15 Dec 2003 22:45:29 -0000	1.52
+++ Src/zsh.h	6 Mar 2004 00:04:53 -0000
@@ -1412,6 +1412,7 @@
     BGNICE,
     BRACECCL,
     BSDECHO,
+    CASEGLOB,
     CBASES,
     CDABLEVARS,
     CHASEDOTS,

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



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