Fork me on GitHub

Gnu Screen: Quicksilver (Kind Of) for Command Line Junkies

If you're a command line junkie, Gnu Screen command is a handy, handy application. It simulates multiple terminals from within one terminal using a relatively easy to learn array of keyboard shortcuts. For example, you can keep top running in one virtual terminal, vi in another, and a bash prompt in another. If you're an OS X user think of it as Quicksilver for the command line.

One annoyance I ran into, however, is the fact that by default screen uses the ctrl-a key to put it into command mode. Ctrl-a is used by default in readline to move the cursor to the beginning of a line and, as bash leverages readline, it's a keystroke that is very useful. Because of this keyboard mapping conflict, I found myself hitting ctrl-a to move the cursor to the beginning of the line and, instead, entering Screen's command mode. Frustrating.

One solution is to change the default keystroke that puts Screen into command mode. To configure screen to use the backtick, for example, add the following line to your .screenrc:

escape `a

An alternative to this method is remapping which bash keystroke moves the cursor to the beginning of the line. You can, for example, change this from ctrl-a to ctrl-b by adding the following line to your .bashrc file:

bind '"\C-b": beginning-of-line'

If you want screen to automatically start when you enter the command line, add the lines below to your ~/.bashrc file.

if [ $TERM != 'screen' ]; then
echo 'Screen is activated.'