GNU Screen is a fantastic terminal "window manager" in that it lets you handle multiple terminals from within one. From a purely aesthetic point of view, Screen can consolidate multiple terminal windows into one. Not only that, but what you run under Screen can be shared with other users or used remotely if you start a Screen session at home and then ssh into your home box from work and resume the Screen session.

Screen provides a number of options and features, many of which are customisable via configuration files. The default configuration file is ~/.screenrc, but you can tell Screen to load alternate configuration files.

Suppose you use Mutt for your e-mail and sit on IRC via Irssi. Both are text-mode clients and are ideal to run under Screen. You can automate the launching of both clients under Screen quite easily, without disrupting default Screen behavior.

To begin, create a shell script and save the contents below as ~/bin/start-screens:

#!/bin/sh
/usr/bin/screen -O -S screens -c ~/.screenrc-startscreens

Next, create the file ~/.screenrc-startscreens with the following contents:

startup_message off
chdir
autodetach on
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'

screen -t shell0 0
screen -t irssi 1 /usr/bin/irssi
screen -t mutt 2 /usr/bin/mutt

This configuration file will start three Screen windows: the first is a standard shell window, the second starts Irssi, and the third starts Mutt. The other options control Screen behavior; the hardstatus line is always present and shows the names of the open windows, the hostname, and the current date/time.

Now simply execute ~/bin/start-screens to begin the Screen session, which will open a terminal at screen 0, Irssi at screen 1, and Mutt at screen 2.

To switch between screens, press [Ctrl]a and the screen number; for example, pressing [Ctrl]a and then 2 will take you to the Mutt screen (Note: the letters are case-sensitive). You can cycle through screens by pressing [Ctrl]a and then [Ctrl]n to move forward in the list or [Ctrl]a and then [Backspace] to move back in the list. To move back to the previous screen, press [Ctrl]a and then [Ctrl]a -- a great way to flip between two screens.

You can also create a new screen by pressing [Ctrl]a and then c, and kill existing screens with [Ctrl]a and then k. To change the name of a screen, press [Ctrl]A and then A. In the above example, the name associated with the Mutt screen is mutt and the name associated with the initial shell is shell0. Pressing [Ctrl]A and then A will change these names, which are shown in the hardstatus line. Note that these shortcuts are case-sensitive. To send an actual [Ctrl]a to the screen, simply send [Ctrl]a and then a.

As well, the [Ctrl]a trigger can be customised; if you find [Ctrl]a is a key command not to your liking, you can modify the screenrc to change it:

escape ^gg

The above would set the trigger to [Ctrl]g, instead of [Ctrl]a.

Open Sourcery This was published in Open Sourcery, check every Monday for more stories

Related links

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

Log in


Sign up | Forgot your password?

  • Staff Aussies to pay more for Win 7

    If you are looking to make some money in these troubled times, perhaps importing copies of Windows 7 could be for you. Read more »

    -- posted by Staff

  • Staff Firefox: Greens want it, 3.5rc2 not up to par

    This week's roundup looks at the situation surrounding a campaign to change Outlook HTML renderer, a Greens MP wants to install Firefox but is restricted and all the photos from the iPhone 3GS launch. Read more »

    -- posted by Staff

  • Chris Duckett Microsoft misses the Outlook point

    Ask designers which mail program is the bane of their existence, and you'll find that Outlook tops the list. The reason why the most popular email reader is also the most painful is simple: it uses Word to render HTML emails. Read more »

    -- posted by Chris Duckett

What's on?