Ah, the wonderful world of the command line. I wouldn’t be able to look at myself in the mirror (and by mirror, I mean reflection in my monitor) if I couldn’t play the shell as if it were a finely tuned 128-key instrument. But I like to add a little pizzaz to the very black-and-white (or black-and-amber, or black-and-green) world of Terminal.
To do this, one adds ANSI color codes to things. Pass a proper flag or two to ls, set CLICOLOR in your environment, and most of all, set your PS1 to something interesting. Here’s mine for my local machine:
PS1='\[\033[35m\]\u@\h\[\033[00m\]:\[\033[94m\]\w\[\033[96m\]\$\[\033[00m\] '
The result looks something like this:
On remote machines, I use this somewhat more typical line so I can distinguish instantly whether I’m in a local or remote window:
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
Which shows up as:
The only gotcha to all this is that on some BSD systems which shall remain nameless, the TERM of xterm-color that Terminal declares isn’t recognized properly for color codes and paging, due to some kind of wacky error in the termcap database. Trying to fix it only netted me a terminal that didn’t work at all, so now in my ~/.profile, I cheat with
TERM=rxvt ; export TERM
Since Apple’s Terminal supports that with full verisimilitude, it all works out. But it’s still an annoying little hack.
For the curious, the little terminal fragments above were done purely with CSS styling. Here’s the code for the pedantic people like myself. Sorry about the pathetic syntax highlighting, my little style plugin was built for programming languages more than general use.
<div style="border: 2px solid gray; font-family: monospace; font-size: 12px; background-color: black; color: white; padding: 4px; margin-bottom: 1em;"> <span style="color: magenta;">gwynne@localhost</span>: <span style="color: #0000ff;">~/Desktop</span> <span style="color: cyan; font-weight: bold;">$</span> <span style="background-color: white;">_</span> </div> <div style="border: 2px solid gray; font-family: monospace; font-size: 12px; background-color: black; color: white; padding: 4px; margin-bottom: 1em;"> <span style="color: #00ff00; font-weight: bold;">gwynne@darkrainfall.org</span>: <span style="color: #0000ff; font-weight: bold;">~/src</span>$ <span style="background-color: white;">_</span> </div>
Interesting note, when using terminal colours in screen in rxvt on linux, it just works out of the box, assuming you have
COLORTERM=”rxvt”
TERM=”screen”
exported, which is usually default.
If you like colours in your terminal, rxvt-unicode-256color is worth checking out.