Skip to content

Configuring Screen

This chapter delivers a ~/.screenrc worth having: the startup splash gone, a scrollback big enough to be useful, a permanent status line naming your windows, and three windows opened ready-made in every new session. Each line is explained, and each effect the lab claims was measured, in transcript screen-lab/transcripts/t05-screenrc.txt. The file itself is in the repository as examples/screenrc.

Where settings live

Screen reads configuration from three places, in order: the compiled-in defaults, the system file /etc/screenrc, and your ~/.screenrc. Later files win where they speak. Two rules govern everything below:

  • The files are read when a session starts. Editing ~/.screenrc does nothing to sessions already running — the single most common configuration confusion there is (chapter 14 keeps the appointment).
  • A line Screen cannot parse is reported at startup, on a screen that waits for a keypress. Annoying and honest: you find out at once, not three chapters later.

The file, line by line

Silence the splash

startup_message off

Removes the copyright screen that otherwise greets every new session. Cosmetic, and the first line in most people's file.

A scrollback that keeps the past

defscrollback 5000

New windows get a 5000-line scrollback (chapter 7 explains what the buffer is). def because it is the default for windows created afterwards; a running window's size is changed from inside, with the scrollback command (Ctrl-A : then scrollback 5000).

The lab measured this one rather than asserting it (transcript t05). A window that printed 1500 lines, captured with hardcopy -h:

Setting Lines kept of 1500 printed
System default (1024) 1048
defscrollback 5000 1503

The extra three lines in each count are the prompt and the command itself. Five thousand is not magic; it is a size at which "the error scrolled away an hour ago" stops happening, bought with a little memory per window.

A status line that names the windows

hardstatus alwayslastline
hardstatus string " %S: %w "

The first line reserves the terminal's bottom row, always, for a status line (the hardstatus, named for the terminals that once had one built in). The second says what goes in it, in Screen's format escapes: %S the session's name, %w the window list — number and title of every window, the one currently shown marked with *.

Drawn by the lab's configured session, from transcript t05:

 tuned: 0 editor  1 shell  2* logs

The format language has more (%H hostname, %c a clock, %n and %t the current window's number and title, colours for the patient); the manual's "String Escapes" section is the full menu, and the line above is a sane place to stop.

Windows, ready-made

screen -t editor 0
screen -t shell 1
screen -t logs 2

The screen command inside a configuration file opens a window when the session starts: title with -t, then the window's number. Every session now begins as the same three-room house, and chapter 6's window keys move between the rooms. Verified in transcript t05 by asking the newborn session for its window list from outside: 0 editor 1 shell 2 logs.

To open a window running something other than a shell, name the program after the number: screen -t top 3 top starts window 3 with top already running in it — and the window closes when the program exits, which is what you want for monitors and what you very much do not want to discover about an editor.

Moving the prefix

If Ctrl-A is a key your fingers need for other work (the shell's and Emacs's "start of line" above all), the escape setting moves Screen's command prefix. It takes two characters: the new command character, and the key that sends the command character itself through to programs:

escape ^Tt

makes Ctrl-T the prefix, and Ctrl-T followed by t a literal Ctrl-T. The lab ran this change for real — transcript screen-lab/transcripts/t07-prefix-escape.txt drives a session whose file contains only that line, and creates its second window with Ctrl-T c, in a session where Ctrl-A c does nothing at all.

Pick the new prefix with care: it should be a control key your other tools do not want. Ctrl-T and Ctrl-O are the usual refugees. And know the cost of moving house: every example in every Screen tutorial, this guide included, is written in Ctrl-A.

Check

Copy examples/screenrc to ~/.screenrc, start a fresh session, and compare against the transcript: the splash is gone, three windows exist before you touch a key (Ctrl-A " lists them), the status line names the session at the bottom, and a window that prints 1500 lines can give all of them back to hardcopy -h.