From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7504 invoked from network); 29 Sep 1997 16:37:49 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 29 Sep 1997 16:37:49 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id MAA06641; Mon, 29 Sep 1997 12:29:55 -0400 (EDT) Resent-Date: Mon, 29 Sep 1997 12:24:48 -0400 (EDT) To: "Bart Schaefer" Cc: unpingco@mpl.ucsd.edu (Jose Unpingco), zsh-users@math.gatech.edu (zsh) Subject: Re: is text file? References: <9709282231.AA23791@cryptica.UCSD.EDU> <970928170607.ZM7789@candle.brasslantern.com> From: Greg Badros Date: 29 Sep 1997 09:25:19 -0700 In-Reply-To: "Bart Schaefer"'s message of "Sun, 28 Sep 1997 17:06:07 -0700" Message-ID: X-Mailer: Gnus v5.4.65/Emacs 19.34 Resent-Message-ID: <"G2u5d2.0.4b1.GPzBq"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1043 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu "Bart Schaefer" writes: > On Sep 28, 3:31pm, Jose Unpingco wrote: > } I usually use PERL's -T in a function to check if a file is ASCII > } or binary. Is there a way to do this using zsh. > > I'm sure Larry Wall will forgive me for saying that perl's -T is a hack. > It reads a chunk of the file and guesses whether the whole file is ASCII > based on the contents of that fragment. > > Zsh's globbing uses only information from readdir() and stat()/lstat(), > and hopefully is going to stay that way. > I disagree. The reason perl's -T exists *even though* it is such a hack is because it is damn useful. I'm sick of accidentally grepping through binaries, and would love a zsh feature that would let me do: grep foo *(T.) # search for foo in all non-binary files Why must zsh's globbing restrict itself to only filesystem meta-information? Yes, I understand a (T) glob modifier would be slower since zsh would have to read the first bit of the file (another seek) but who cares -- users time in being able to restrict the set of files glob more usefully is worth a lot. Yes, there are other ways to restrict a glob in a similar way (for example, using a script that echos its arguments after removing names of binary files [using file]), but they are far worse hacks than letting zsh do it for you. Perhaps it would seem less hacky if there were a general user-programmable glob feature that would call a function on each filename and accept that file for the glob iff the function returns 0. Then the way that you determine what kind of file a filename points to is not part of the shell, but the nice glob modifier interface is permitted. > An approximation might be (with extendedglob set): > > % ls **/*~*(${~${(j/|/)fignore}})(.) > > That is, all plain files that do not have extensions listed in `fignore'. > You could change (.) to (.^*) to omit executables, but that would also > omit most shell scripts. > > (Somebody tell me why the extra ${~...} is needed in that expression.) I'm fairly certain I'll never type such an incantation (how long did it take to dream it up? :-) ). Greg J. Badros gjb@cs.washington.edu Seattle, WA USA http://www.cs.washington.edu/homes/gjb