Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tlug: ls colorful



You(John Seebach) wrote:
> > A possible improvement would be
> >    alias ls="ls --color=auto"
> > which will disable color output if the output is not a terminal.
> Right, Except then if I want to look at a really big directory and pipe the
> output through more, I lose my colored output (more's not a terminal).

Ah. I'm a "less" kind of a person, and less doesn't let escape codes
through by default, so this didn't occur to me. 

> Here's what I do to have my cake and eat it, too:
> 
> 	export LS_OPTIONS='--color=auto'
> 	export LS_PG_OPTIONS='--color'
> 	eval `dircolors /etc/lscolors`     # I had to change the colours 
> 								# because I couldn't read 
> 								# blue on black very well
> 	alias ls='ls $LS_OPTIONS'
> 	alias l='ls $LS_OPTIONS -l'
> 	alias la='ls $LS_OPTIONS -A'
> 	alias ll='ls $LS_PG_OPTIONS -l $* | more'
> 	alias lla='ls $LS_PG_OPTIONS -lA $* | more' 
> 
> There's probably a better way to do this, of course. 

There Is More Than One Way To Do It. (That's the perl mantra,
actually, but you get the idea.) Anyway, here are two ideas:

bash or zsh shell function:
function ml {
   ls --color=yes $* | more   
}

tcsh alias:
alias ml 'ls --color=yes \!* | more'

Bourne shell script:
$ cat > ~/bin/ml
#! /bin/sh
exec ls --color=yes $* | more
^D

They basically do the same thing, except that you can't use the tcsh
alias version of ml within other macros and the shell script version
is available no matter what shell you are using.

-- 
Shimpei Yamashita             <http://www2.gol.com/users/shimpei/>
--------------------------------------------------------------------
Next Nomikai Meeting: February 18 (Fri) 19:00 Tengu TokyoEkiMae
Next Technical Meeting:  March 11 (Sat) 13:00 Temple University Japan
* Topic: TBD
--------------------------------------------------------------------
more info: http://www.tlug.gr.jp        Sponsor: Global Online Japan

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links