zsh-users
 help / color / mirror / code / Atom feed
From: Greg Badros <gjb@cs.washington.edu>
To: "Bart Schaefer" <schaefer@brasslantern.com>
Cc: unpingco@mpl.ucsd.edu (Jose Unpingco), zsh-users@math.gatech.edu (zsh)
Subject: Re: is text file?
Date: 29 Sep 1997 09:25:19 -0700	[thread overview]
Message-ID: <qrrn2kw84uo.fsf@demille.cs.washington.edu> (raw)
In-Reply-To: "Bart Schaefer"'s message of "Sun, 28 Sep 1997 17:06:07 -0700"

"Bart Schaefer" <schaefer@brasslantern.com> 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


  reply	other threads:[~1997-09-29 16:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-28 22:31 Jose Unpingco
1997-09-29  0:06 ` Bart Schaefer
1997-09-29 16:25   ` Greg Badros [this message]
1997-09-29 17:44     ` Bart Schaefer
1997-09-29 21:28     ` TGAPE!
1997-09-30  3:53       ` Bart Schaefer
1997-09-30 16:19       ` Greg Badros
1997-09-30 18:56         ` Bart Schaefer
1997-09-30 20:02           ` Greg Badros

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=qrrn2kw84uo.fsf@demille.cs.washington.edu \
    --to=gjb@cs.washington.edu \
    --cc=schaefer@brasslantern.com \
    --cc=unpingco@mpl.ucsd.edu \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).