Customizing your xTerm and Terminal: I. Color

by saurav on August 25, 2010

As our eyes spend most of our days looking at the xTerminal (xTerm, xgTerm, uxTerm, or Terminal.app) any relief is always welcome. Unfortunately, the default for the xTerminal (or most applications) is black text on white background which means you are staring at white, i.e., light, most of the time. In addition, your eyes have to constantly adjust between the two extremes of the color spectrum. Hence, even while providing the highest contrast, this color combination tends to strain your eyes. The same is true for light text on dark background, which has been the fad for some web designers these days; please avoid either combination! As far as the eyes are concerned, green/yellow text on a black background (or off-white on dark gray) is the most soothing for the eyes.

One way to change the colors on your Mac’s X11 is to add the following lines to your .Xdefaults, which lives in your home directory:

xterm*Background:               black
xterm*Foreground:               green
xterm*cursorColor:              LightBlue
xterm*pointerShape:             arrow
xterm*pointerColor:             blue

Note I changed the cursor and pointer properties as well. If .Xdefaults does not exist in your home directory, feel free to create one. For Terminal.app, you can simply use the GUI preferences; it does not read .Xdefaults.

While you are at it, you might want to change the colors for the ‘ls’ commands as well for two different reasons: (i) the defaults do not work well with your new green-on-black xTerminal and (ii) the right color coding instantly identifies the file type. To change the color coding, first you need to make sure color option is turned on; add the following line to .bashrc for xTerminals or .bash_profile for Terminal.app (or .cshrc for both if you use the C shell)**:

export CLICOLOR=TRUE

Adding a ‘-F’ flag to the alias will result in a slash (‘/’) after directory names. Then to define the foreground and background colors for eleven different filetypes, you need to redefine the LSCOLORS (LS_COLORS for UNIX) parameter in the .bashrc or .bash_profile:

export LSCOLORS=Gxfxbxdxcxegedabagacad

which specifies eleven sets of colors (11x fb). This results in green filenames, bold-green executables, blue directories, yellow symlinks, and so on (see above screenshot); I prefer not to use a background color for normal filetypes. If you are curious, the eleven filetypes are:

1. directory
2. symbolic link
3. socket
4. pipe
5. executable
6. block special
7. character special
8. executable with setuid bit set
9. executable with setgid bit set
10. directory writable to others, with sticky bit
11. directory writable to others, without sticky bit

If you want to explore more colors, you will need to use the standard ANSI colors:

a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background

Hopefully this provides some respite for your eyes! Remember, you can do the same for emacs (in your .emacs file) and even for gmail!

** Original post had an extraneous error: as John pointed out OS X’s ‘ls’ does not handle the “–color=auto” option.

{ 11 comments… read them below or add one }

1 John August 25, 2010 at 7:18 am

Be aware that /bin/ls on a Mac is not GNU ls:

$ /bin/ls --color=auto
/bin/ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

But, of course, you can install your own version: I use one from Macports.

$ /opt/local/bin/ls --version
ls (GNU coreutils) 8.4
[...]
$ /opt/local/bin/ls --color=auto
[works fine]

If you’re using Terminal.app on OS X 10.5+ (and why wouldn’t you? It’s actually pretty good…), you might be frustrated by an inability to customise the colours (you can say “make this blue”, but not specify which shade of blue). Fortunately, there is a solution.

Reply

2 Joy August 25, 2010 at 11:43 pm

Bummer, when I source my .cshrc, it doesn’t recognize the ‘export’ command. I’m using the X11 xterm on a Mac 10.5.8

Overall, I like the green on black – it feels really retro!

Reply

3 Kelle August 26, 2010 at 7:19 am

Joy, use ‘setenv’ syntax instead of ‘export’

John, for the OS X ls, you can use setenv CLICOLOR “true” instead of ls –color=auto

in sum, for tcsh on OS X:

alias ls 'ls -FG'
#F is for trailing slashes, G is for color
setenv TERM "xterm-color"
setenv CLICOLOR "true"
setenv LSCOLORS "Gxfxcxdxcxegedabagacad"

Reply

4 John August 26, 2010 at 8:38 am

Kelle — indeed: if you want to use OS X’s ls, it’s certainly possible. However, the instructions in the article are potentially misleading.

Personally, I reckon having command line tools work in the same way whichever machine I’m using (OS X, Linux, whatever) is worth the few minutes it takes to install GNU coreutils. Your mileage may vary, etc etc.

Reply

5 Saurav August 26, 2010 at 9:48 am

John, Thanks for catching that bug. I have modified the article to reflect that.

Reply

6 Joy August 26, 2010 at 10:38 am

Thank you! This does look very fine, and I enjoy having the directories looking different than the files in the list.

Reply

7 John August 27, 2010 at 6:05 am

Hey Saurav — glad to be of help! Nice article.

Reply

8 dave July 23, 2011 at 11:22 pm

Thanks to you I finally understand how to customize my file listings in Xterm 🙂

Reply

9 jayess August 18, 2011 at 2:45 am

so thank you, I’d changed my xterm defaults once before but an upgrade borked these settings and I couldn’t remember where. Just one thing…”The same is true for light text on dark background, which has been the fad for some web designers these days; please avoid either combination!” Written in white on a black webpage.

Reply

10 Kelle August 18, 2011 at 9:10 am

there’s a difference in logic between choosing a color scheme you choose for a webpage that you might spend a couple minutes on vs your xterm which you might stare at for hours a day. i’m not going to make the site green on black!

11 ayekat October 6, 2011 at 9:43 am

man ls
GNU/Linux: ls --color=auto
BSD: ls -G

Reply

Leave a Comment

Previous post:

Next post: