From: dennisf@denix.elk.miles.com (Dennis Flaherty) Subject: Re: [Q] How to colorize directory listings? Date: Sun, 9 May 1993 19:44:46 GMT
In article <HERMIT.93May9142230@am.ucsc.edu> hermit@cats.UCSC.EDU (William R. Ward) writes:
> In article <gilC6IIrq.70s@netcom.com>, gil@netcom.com (Gilbert Nardo) writes:
> ) A note of caution when using this ls: some scripts rely on
> ) getting names via ls, but with the color option the command returns
> ) filenames with prepended escape codes (set color codes). This becomes
> ) a problem when the scripts are doing things like generating makefiles
> ) which require exact target name matching. If you are set on using
> ) the ls with color, then you may have to tack on the --no-color option
> ) for these cases (I don't know if there's an environment variable you
> ) can set to have this toggle on and off).
>
> Well, I know that ls pays attention to whether it's running on a TTY
> or not, to determine whether it should output a single-column or
> multi-column format. It would seem logical to me that this same
> criterion could be used to suppress colors if run in a script.
That would seem to be a reasonable solution; ls could check to see if
its stdout is a tty, and generate the ansi color escape sequences if it
is. That's not hard to check for.
The trouble is that there are many tty types that choke on the ansi
sequences. I could make "-o" and isatty(stdout) both necessary
conditions to deal with this, but you still wouldn't be able to paginate
a color directory listing with "less -r" since "less" isn't a tty.
Having an alias of "ls" for "ls -o" in one's shell "rc" file seems to be
the best way, short of adding two different switches to ls.
The patch to fileutils-3.5 to colorize directory listings with support
for environment-variable customization and 8-bit filenames should be out
this week. If anyone has more ideas to add, send me email.
--
Dennis T. Flaherty Home: dennisf@denix.elk.miles.com
Flaherty Nanobreweries, Work: dennisf@se01.elk.miles.com
Ales Division School: dflahert@chekov.helios.nd.edu
Oatmeal Stout: It's the Right Thing to Drink!