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

Case insensitive completion (Re: zsh - new user with questions)



On Aug 19,  5:09pm, Stephen Riehm wrote:
} Subject: Re: zsh - new user with questions
}
} All that is required is that all routines that compare file names need
} to convert both strings for comparison to lower (or upper) case before
} comparison.

Minor nit:  It can't be _all_ routines that compare file names, because
the files README ReadMe Readme readme and rEaDmE might all exist in the
same directory.  At some point you have to notice case to identify the
one you really mean.  Case-insenstive globbing is much more dangerous
than case-insensitive completion, particularly given multios (where e.g.
"echo foo > r*me" might clobber all five files).

In any case (pun intended), here's a bit of a hack to make the multicomp
function be case-insensitive in the ASCII set, including making `-' and
`_' interchangable.  It should be obvious how to add other mappings; for
example, to equate comma and period, append :gs/,/./:gs/./.,/

There might be a simpler way to achieve this, but short of using process
substitution I couldn't think of one.

Index: Functions/multicomp
===================================================================
--- multicomp	1998/06/01 17:08:43	1.1.1.1
+++ multicomp	1998/08/19 17:40:06
@@ -53,7 +53,17 @@
     else
       wild='*'
     fi
-    reply=(${sofar}"${head}${wild}${globdir}")
+
+    # Simulate case-insensitive globbing for ASCII characters
+    wild="[${(j(][))${(s())head:l}}]${wild}"	# :gs/a/[a]/ etc.
+    # The following could all be one expansion, but for readability:
+    wild=$wild:gs/a/aA/:gs/b/bB/:gs/c/cC/:gs/d/dD/:gs/e/eE/:gs/f/fF/
+    wild=$wild:gs/g/gG/:gs/h/hH/:gs/i/iI/:gs/j/jJ/:gs/k/kK/:gs/l/lL/
+    wild=$wild:gs/m/mM/:gs/n/nN/:gs/o/oO/:gs/p/pP/:gs/q/qQ/:gs/r/rR/
+    wild=$wild:gs/s/sS/:gs/t/tT/:gs/u/uU/:gs/v/vV/:gs/w/wW/:gs/x/xX/
+    wild=$wild:gs/y/yY/:gs/z/zZ/:gs/-/_/:gs/_/-_/
+
+    reply=(${sofar}"${wild}${globdir}")
     reply=(${~reply})
   fi
 

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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