Configure Terminal on Mac OS X January 28, 2009

The Terminal application on Mac OS X

Every time someone asks me for help about something geek on a Mac, I often prefer to use the Terminal, because I never got used to editing a configuration file under /etc with a graphical text editor. Don’t misunderstand me, I am not a Terminal addict, and I often prefer using graphical tools that are extremely integrated with Mac OS X: for example, I wouldn’t code in C or C++ with something else than Xcode, which turns out to be an incredible IDE. But for some other things, I still launch this Terminal, and there are a few things in its default configuration I never liked, such as the behavior of the keys page up/page down, home/end, etc.

So, let me tell you how you can configure your Terminal like I did on my mac, running Mac OS X Snow Leopard 10.6.4.

General settings

First, launch Terminal (using Spotlight, my favorite!), open the Preferences window, and click on Settings. Here, you will see on the left a list of predefined themes with different colors. If you decide to change your default theme, just click on it, and then click the button Default. I always preferred a black terminal with white text, so I chose the theme called Pro. Then, to be sure this will work (specially if you already changed some preferences here), you can click on the cogwheel button next to the minus button, and choose Restore Defaults.

In order to have a much more beautiful text on your terminal, you should check the box Antialias text.

If, like me, you don’t understand why a Terminal window doesn’t close automatically once the shell exits (for example, when using the common shortcut ^+D), then you should go to the Shell tab, and under When the shell exits: select Close the window.

Keys and actions

Let’s go to the tricky part: keys and actions. Go to the Keyboard tab, and set the following keys to the corresponding actions:

Key & modifier Action Corresponding string What to type?
control cursor left send string to shell \033b esc B
control cursor right send string to shell \033f esc F
home send string to shell \001 ^+A
end send string to shell \005 ^+E
page up send string to shell \033[5~ esc [5~
page down send string to shell \033[6~ esc [6~
shift home scroll to start of buffer
shift end scroll to end of buffer
shift page up scroll to previous page in buffer
shift page down scroll to next page in buffer

As you will see, when typing the corresponding string in the text area under send string to shell, every keystroke you type can create a weird output. So you should just type what is in the last column, knowing that esc represents the escape button, that ^ is the control button, and that + means press both keys at the same time.

What if you use a remote screen with ssh on a Linux server?

Everything should work properly now… except if you’re like me and you often use a screen on Linux boxes through ssh. If you didn’t even understand this sentence, you should just skip this part.

In this case, your backspace key won’t work properly on the remote screen, and it’s a shame. To solve this problem, the best solution I found was to upload the file /usr/share/terminfo/78/xterm-color of the Mac to the server (with scp for instance, or with the excellent Cyberduck application through SFTP) and to do the following on the server:

mkdir -p ~/.terminfo/x/
mv ~/path/to/xterm-color ~/.terminfo/x/

This trick works for me, but if you use a remote screen on many different Linux servers, then it can be a pain. Hopefully, like me, you will only need it for a single account on a single Linux server where you run irssi in a screen; in that case, you just found the solution for the backspace problem.

The end

And you’re done! Just quit the Terminal application, launch it again. That’s it!

One last word, you should also look at the feature called Window groups: it allows you to save the way several Terminal windows are on the screen, and it can be useful for someone who often uses more than one Terminal window at a time.

Enjoy!

Leave a Reply