Terminal Tips: Using the Command Line With Style



As great and as easy as the OS X user interface is, sometimes it is quicker or necessary to jump into the deep dark bowels of your system on the command line. OS X ships with the very competent Terminal.app that allows easy access to this, but the default view into your machine is dull and boring. It doesn’t have to be. Here are a few tips to style things up a bit.


Visor has been mentioned in the past here at TheAppleBlog, and for good reason. It works as an add-on to Terminal to give you a ‘quake-style’ drop down HUD interface. You press the hotkey and a terminal drops down from out of nowhere in a fast, convenient, out-of-the-way manner — complete with tab support.

If you search for Visor on the web, you’ll most likely end up at its Google Code page, where it seems that the most up-to-date version is 1.5a1 from November 2007. Fear not, for Visor is still being developed and the latest version is actually 1.81, released on March 5 of this year.

To download it you need to go its GitHub page and click the link to the pre-compiled binary. Follow the instructions to install it. 1.81 adds more options to play with, but most importantly for me, is that it enables full custom key-stroke support — so any keys defined in Terminal are usable in Visor.

Hiding Visor’s Terminal

Because Visor hooks into the Terminal application, it needs to be running and cluttering up your dock and command-tab icons all the time. Fortunately, there is a nice hack that will get Visor running ‘invisibly’ without any sign of Terminal.app running. This makes for a cleaner desktop experience while still leaving a terminal only one keystroke away.

To do this you need a plist editor — if you have the OS X Developer Tools installed you already have the Property List Editor app. If not you can download PlistEditPro which has a free trial period and will do the trick for you. The following steps assume you already have Visor installed and working.

  1. With Finder, show the package contents of ~/Library/Application Support/SIMBL/Plugins/Visor.bundle (right click to access this option) and load the file Contents/Info.plist in your plist editor. From the root node, expand SIMBLTargetApplications, then Item 1 and change BundleIdentifier from com.apple.Terminal to com.apple.Terminal_Visor
  2. Make a copy of Terminal.app that is in /Applications/Utilities and call this copy Terminal_Visor.app
  3. With Finder, show the package contents of the new Terminal_Visor.app and open its Contents/Info.plist file in your plist editor. From the root node, change CFBundleIdentifier to com.apple.Terminal_Visor.
  4. Run Terminal_Visor and make sure Visor works properly. Configure all Terminal preferences and settings to your liking. Right click on the Terminal_Visor dock icon and select Open At Login to make it starts up automatically.
  5. With Finder, show the package contents of /Applications/Utilities/Terminal_Visor.app and open its Contents/Info.plist file in your plist editor. Add a new Number entry at the bottom called LSUIElement and set its value to 1. (This entry can also be known by its descriptive name of “Application is agent (UIElement)”). Relaunch Terminal_Visor and there will be no sign that its running except when you press your Visor hotkey.

Now you have less clutter with the same power. To make Terminal_Visor visible again (to change preferences) change the LSUIElement value back to 0 in its Info.plist. To quit Terminal_Visor when it is running, you can toggle the visor terminal with a hot-key and then press Command + Q.

Colored Directory Listings


By default when you type the ls command you get a dull black and white listing. This is very old school and in this day and age we have the technological marvel of colored directory listings. This shows different file types in different colors, allowing you to be quickly informed with a simple glance. To enable support for this, all you need to do is create (or open it if it already exists) a file called ~.bash_profile in a text editor (note the dot before the name — this is a hidden file). Add the following lines:

export CLICOLOR=1

export LSCOLORS=ExFxCxDxBxegedabagacad

Start a new terminal session and, lo and behold, you have a colored directory listing. You can customize what colors are used by modifying the LSCOLORS variable, which defines what type of file is shown as a particular color. A nifty tool to help you come up with the appropriate value for this is the LSCOLORS Generator.

A More Useful Command Prompt

When you start a terminal session you are normally greeted with a white prompt that looks something like BedPro:~ Bed$, where “BedPro” is your machine name, “~” is the currently directory you’re in and “Bed” is your user name. This can be changed to almost anything you like and it can be helpful to do so to quickly differentiate the prompt from command output, and to show more information such as the fully qualified current directory path (like “UsersBedDocuments” rather than just “Documents”). My prompt (see screenshot above) is separated from the last command output by a blank line, lists who I am on what machine, and the full directory path. Then I have a blank line to type at.

You can configure a custom prompt by creating (or editing, if it already exists) the text file ~/.bash_profile and adding a line like mine:

export PS1="n[e[1;40;30m]u@h:wn> [e[0m]"

The u@h:w gives me username@host:fulldirectory while the n is a newline. The other codes are the color definitions.

For a full list of codes and colors you can use, see Bash Prompt Escape Sequences and Bash Prompt Colors.

Tweaking Colors

Colors can be rendered in various ways by Terminal.app, so in addition to setting the ls and prompt colors in your .bash_profile, you may also need to tweak Terminal’s settings to achieve the results you like. These can be found in the Settings dialog. In particular I like to uncheck using bold fonts, and check using bright colors instead.


Any other tips?

Are there any other Terminal add-ons you use that are indispensable? Have any other tips for a more stylish experience? Let us know in the comments.



I would suggest to activate the “use option as meta key” setting under settings -> keyboard. Thus you can use many Bash-shortcuts. For example, if you press M-. in the shell, it repeats the last used argument. It can help:

$ mv ~/some/complicated/long/path

Then, a “cd M-.” becomes:

$ cd ~/some/complicated/long/path

Tada, lots of typing saved, which is why in the end of the day we use the shell — to be faster.

Michael Galassi

I often add .cdinrc and .cdoutrc files in directories in which specific activities take place (eg; building source for a project) and do things like change prompt, set environment variables, and what not from these files. I then cause their automatic invocation by adding the following function to my .bash_profile:

cd() {
[ $EUID -ne 0 ] &*)
. .cdoutrc
case $# in
builtin cd
builtin cd “$@”
builtin cd “${PWD%${1}*}${2}${PWD#*${1}}”
builtin cd “$@”
[ $? -eq 0 ] &*)
. .cdinrc
# restore $? to 0 for use with “cd xxx && yyy”
export -f cd

As an added bonus if you invoke “cd” with two arguments the first string in the current directory will be replaced by the second argument and the resulting directory will be switched to. If for example I’m in a directoy called “/Users/mg/version1” and I type “cd 1 2” I will find myself in the directory “/Users/mg/version2”.

Note that any .cdinrc and .cdoutrc files must be executable, they must be in a sub-directory of your $HOME, and you cannot be root (EUID 0). Of course you can change all that.


One of the things I use most in terminal (linux and mac) is bash-completion. It can be installed via fink and mac ports and it enhances the “intelligence” of bash autocompletion feature. It will autocomplete not only file names and paths, but also will search for optional commands for example.
It has more capabilities so better take a look at the developer’s site http://www.caliban.org/bash/index.shtml

Leland Clemmons

I love Blurminal. Basically just blurs the terminal background when the opacity isn’t 100%. Bad thing is, it needs SIMBL.

Jeff Grossman

I love the colored “ls” — but the colors disappear if you pipe through “more” or “less” (which is useful in long directories, as you know). Any way to keep the colors?

Markian Hlynka

You forgot to add that you can set the prompt to modify the terminal’s title bar. For example, I have:

[e]2;working in w a[e[32m]u[e[0m]@[e[32;1m]h[e[0m]:[e[0me[33;40m]W > [e[0m]

The first part of that sets the title bar to display the working directory. I don’t remember what the rest does!

BJ Neilsen

The biggest thing that drove me crazy when I started using Terminal was that it seemed like I couldn’t change the keypress rate (which is unbearable slow at its default). Try typing a huge cvs commit command and then you realize that you mistyped a filename halfway through the command. SO frustrating.

I found later the simple fix to this is to go into Keyboard preferences and change the keypress rate and max it out. This does mean that everywhere in os x the keypress rate will be faster, but this is a welcome change to the default snail-paced speed.

Comments are closed.