Torn as I now am between my iMac and my laptop (Ubuntu linux), I invariably find myself using both: OS X at the desk, Ubuntu on the couch. My brief tenure in linuxland taught me to embrace the CLI (Command Line Interface), and upon returning to mactopia, I find I use the CLI almost exclusively. (That and VIM. I decided early on that rather than waste time learning yet another GUI editor, I’d take the opportunity to learn VIM and promptly fell in love. I’m typing this in VIM right now, even as my TextMate icon stares up at me from the dock.) For me, Linux and Darwin are sufficiently similar that I’m at home on either and I’ve come to respect their subtle differences.
That said, one thing I really liked about the default bash terminal in Ubuntu was its color, so I sought to bring this feature over to my OS X Terminal. Using ls with color makes things faster—colors can tell you about files in ways that ls -F never could. To enable this in OS X (bash), you’ll need to add some options to your .profile:
export CLICOLOR=1
export TERM=xterm-color
The first line turns on color, and the second ensures that your terminal is declared as color capable. While this will work as advertised, it won’t necessarily look very good if you use a dark background. By default, directories are listed in blue, and while this looks good in Ubuntu it’s just too dark on the Mac. For those of us who rock a black background, you might want to change the ls colors.
export LSCOLORS=gxfxcxdxbxegedabagacad # cyan directories
In the above example, I’m using cyan for directories; this is a fair compromise and looks nice in both OS X and Ubuntu. If you want to know about each of the color codes above, they’re listed in the ls manual (man ls).
For the complete linux effect on OS X, a green prompt will also be necessary. Without getting in the sordid details of customizing your prompt (it’s a long and arduous tale that I’ll save for another article), I offer this:
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '
When we put it all together, we get a comfortable and portable CLI that looks quite nice, no matter where you’re logging in from.
# colors
export CLICOLOR=1
export TERM=xterm-color
export LSCOLORS=gxgxcxdxbxegedabagacad # cyan directories
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '