zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Greg Badros <gjb@cs.washington.edu>
Cc: zsh-users@math.gatech.edu
Subject: Re: is text file?
Date: Tue, 30 Sep 1997 11:56:12 -0700	[thread overview]
Message-ID: <970930115613.ZM17003@candle.brasslantern.com> (raw)
In-Reply-To: <qrrsoum7p0d.fsf@demille.cs.washington.edu>

On Sep 30,  9:19am, Greg Badros wrote:
} Subject: Re: is text file?
}
} ... you simply add a built-in test to zsh that is true iff that
} argument is a text file.

You could write this yourself as a module using 3.1.x.

Anyway, the following works in 3.0.5 (but not earlier because typeset -U
didn't work properly):

    text() {
      local ascii=(8 9 10 12 13 {32..126})
      local -U bytes
      for file
      do
	bytes=( $ascii $(od -An -td1 -N 256 $file) )
	[[ $#bytes -eq $#ascii ]] && echo $file
      done
    }

    grep foo $(text **/*(-.))

Increase or decrease 256 in the `od' command to get more or less accurate
guesses as to whether a file is text or not.  Adjust `ascii' if you want
to include a larger character set.  Add `[[ -f $file ]] || continue' if
you don't want to worry about the (-.) in the glob pattern.

This does assume GNU `od', I guess.

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


  reply	other threads:[~1997-09-30 19:01 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
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 [this message]
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=970930115613.ZM17003@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=gjb@cs.washington.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).