[comp.unix.i386] Adding a little color to your ls output

gmd@pulsar.mv.COM (George MacDonald) (03/19/90)

Here is little q&d ksh function which colorizes the output from ls in the
following way.

	Directories  - cyan
	Executable files - red
	regular files - white



function ls
{
/bin/ls -CF $* | sed -e 's;\([a-zA-Z0-9._+-]*\)/;ESC[36m\1ESC[0m ;g' -e 's;\([a-zA-Z0-9._+-]*\)\*;ESC[1mESC[31m\1ESC[0m ;g'
}

I removed the real escape characters and put in their place "ESC", so just
edit the file to put the escape characters back. Remember in vi insert mode
type control-v then escape to put an escape in the file. I put this in
my .kshrc file and in my .profile I set the prompt to green with


PS1=\(`hostname`-$LOGNAME\)
PS1="ESC[32m$PS1ESC[0m"
export PS1 


In case you want to play with the colors the values are

30 - Black (Not much use, unless you use reverse video &| a background 
     color as well)
31 - red
32 - green
33 - brown
34 - blue
35 - purple
36 - cyan

Preceding these with the bold enable command sequence (ESC[1m) yields

30 - grey
31 - light red
32 - light green
33 - yellow
34 - light blue
35 - light purple
36 - light cyan

If you want to get real outrageous then you can also set the background
charater cell color with ESC[4?m, where ? is 0-6 yeilding the colors above.

Enjoy,

      /\ George MacDonald, Pulsar Software Inc. - Unix Software Consultants
_____/  \  _____  ..{harvard,decvax}!zinn!pulsar!gmd or gmd@pulsar.mv.com
         \/   36 Hickory Ln,  Windham, N.H.  03087  Tel (603)-434-2614