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.
Be aware that /bin/ls on a Mac is not GNU ls:
But, of course, you can install your own version: I use one from Macports.
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.
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!
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:
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.
John, Thanks for catching that bug. I have modified the article to reflect that.
Thank you! This does look very fine, and I enjoy having the directories looking different than the files in the list.
Hey Saurav — glad to be of help! Nice article.
Thanks to you I finally understand how to customize my file listings in Xterm 🙂
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.
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!
man ls
GNU/Linux:
ls --color=auto
BSD:
ls -G