With a little side of applesauce...

Thursday, February 1, 2007

changing directory listing colors

Just figured out how to customize the coloring of directory listings in BASH.

1. dircolors = command used to print out color configuration to STDOUT. (use “–print-database” to print out ALL configuration settings).
2. LS_COLORS = environment variable used to set dircolor configuration for BASH

HOW-TO:

1. create new file containing contents of current LS_COLORS envvar

dircolors > ~/.bash_dircolors

2. modify the contents of ~/.bash_dircolors according to the following key:

Attribute codes are 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed, text color codes are 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white, and background color codes are 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white. Here are the some useful types:

no: normal, global default, although everything should be something.
fi: normal file
di: directory
ln: symbolic link
pi: FIFO, pipe
so: socket
bd: block device driver
cd: character device driver
or: orphan, symlink to nonexistent file
ex: files with execute permission

(http://billharlan.com/pub/papers/Gnu_Linux_Miscellaneous.html)

3. source the file to test:

source ~/.bash_dircolors

4. When happy with changes, add the following to .bash_profile, to source .bash_dircolors when you login:

# include .bash_dircolors if it exists
if [ -f ~/.bash_dircolors ]; then
. ~/.bash_dircolors
fi

NOTES:

1. Here is an example of the LS_COLORS

LS_COLORS=’no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:’;
export LS_COLORS

2. To add a background color, change the following:

ln=01;36

To:

ln=01;36;40

No comments: