GNU 'screen' Status Line(s)

Please at least read GNU Screen Basics, and preferably GNU Screen, Part 2 as well.

The GNU screen status line is configured with a string that - like the Bash Prompts I've spent so much time working on - looks like inline garbage. Here's the one I'm using right now:

hardstatus alwayslastline "%{= bR}[%{= bY}%H%{= bR}]%{= bY} %n%{= bR}:%{= bY}%t  %{= bw}%W %=%{= br}[%{= bY}%h%{= bR}]"

Note

I'm recreating the visual representation of the status bars with HTML styles. They won't be entirely accurate (particularly the spacing), but probably more readable than screenshots.

Let's work up to that with progressive examples.

Start with a very basic configuration:

# make this your ~/.screenrc
startup_message off
hardstatus alwayslastline

When you start screen, you'll now have a line at the bottom of the screen that looks like this:

[screen 0: bash] giles@sli7-f:~

I use a black background in my terminals: so what you see above is black-on-white, essentially inverted colours. My username is "giles," and my hostname is "sli7-f."

But this doesn't show us a list of our other screen windows:

hardstatus alwayslastline "%H    %w"

Using this, if I have two windows, the statusbar looks like this:

sli7-f 0 bash 1* bash

%H gets us the local hostname, and %w shows a list of all windows - both their number and their name, with the '*' indicating which one is active.

However, if you've seen my Bash Prompts, you know I like colours. So let's get some colours (and this is where it starts getting very hard to read).

hardstatus alwayslastline "%{= Y}%H    %{= C}%w"

This is (roughly) what it looks like:

sli7-f    0 bash   1* bash        

I'd prefer the whole thing on a blue background:

hardstatus alwayslastline "%{= bY}%H    %{+ C}%w"

The result:

sli7-f    0 bash   1* bash        

I haven't addressed how the colours are handled yet - and this one is doing it differently, so I'd better cover it. %{= Y} means "set the colour to yellow." But that's not all it means: = means "override all previous colour settings." The space immediately after the = is for an attribute setting, a single letter that denotes dim, underline, bold, etc., which I generally don't use. The next item is Y which means "bold Yellow foreground". But notice when we get to the next version I set %{= bY} - if there are two colour codes, the first (in this case b for "blue") is the background. In this example I change just the foreground colour with %{+ C} - the + means to add the colour, only changing what it specifies, in this case C for "bold Cyan" over-rules the existing foreground "bold Yellow" but leaves the background colour alone. Look for the 'STRING ESCAPES' section of the man page for available codes.

Finally, let's get back to the one we started with.

hardstatus alwayslastline "%{= bR}[%{= bY}%H%{= bR}]%{= bY} %n%{= bR}:%{= bY}%t  %{= bw}%W %=%{= br}[%{= bY}%h%{= bR}]"

The result:

[sli7-f] 2:bash    0 bash   1 bash              [giles@sli7-f:~]

We start with a bold red on blue background %{= bR} - and there's only one character printed in that colour scheme, a literal "[" (square bracket). We then switch to bold yellow on blue. Where this gets different is with %n, %t, and %W. Respectively, these are the number of the current window, the title of the current window, and the numbers/titles of all the non-current sessions. At the end of the line (the last section is floated to the right with %=) we have the "hardstatus" you've seen before, %H (again in red square brackets).

If you don't want the status line to always be there, "always" isn't a required part - but because I always want the status line to show, I haven't explored how it behaves without that. If you prefer your status bar at the top, use alwaysfirstline.

There's another form of labelling available: by default each split is labelled with a plain white bar (that's the default colour with my black background terminals) and black lettering showing just the window number and name. You can make this fancier with the 'caption' command:

caption splitonly "%{= bR}[%{= bY}%n%{= bR}:%{= bY}%t%{= bR}]%{= bY}%=%{= bR}[%{= bY}%h%{= bR}]"

This duplicates a lot of the material in the 'hardstatus' line, so this is more of a starting point than a good 'caption' line. I usually don't use splits, so all I want is the 'hardstatus' and I haven't put much effort into getting the 'caption' information looking good.

There's much, much more you can do with these status lines, including conditionals that I don't understand yet (they look like inline garbage too, but more complex inline garbage ...).