Customizing your xTerm and Terminal: I. Color

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… add one
  • John Aug 25, 2010 @ 7:18

    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.

  • Joy Aug 25, 2010 @ 23:43

    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!

  • Kelle Aug 26, 2010 @ 7:19

    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"
    
  • John Aug 26, 2010 @ 8:38

    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.

  • Saurav Aug 26, 2010 @ 9:48

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

  • Joy Aug 26, 2010 @ 10:38

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

  • John Aug 27, 2010 @ 6:05

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

  • dave Jul 23, 2011 @ 23:22

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

  • jayess Aug 18, 2011 @ 2:45

    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.

    • Kelle Aug 18, 2011 @ 9:10

      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!

  • ayekat Oct 6, 2011 @ 9:43

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

Leave a Reply

Your email address will not be published. Required fields are marked *