Posted by Steve on Mon 5 Nov 2007 at 10:11
Many people here use GNU Screen, and I've not seen extensive coverage of the things you can do with the status-line in the past, so I thought a brief overview of a couple of visual settings wouldn't be amiss. Read on for more details.
GNU screen, which we've previously introduced, is a small utility which may be used to leave sessions running when you've logged out, or run multiple console applications in only one terminal. There are many things you can do with it which we'll not cover here, instead we'll look at the status bar.
There are two types of status-bar you may have within a GNU Screen session:
Whats the difference between them? Well the hardstatus line is used for status messages from screen - for example to alert you to activity, or other similar messages. The caption line is usually only shown if there is more than one window open, and allows you to view details of them.
As an example add this to your ~/.screenrc file:
caption string "%w" hardstatus alwayslastline "This is a test..."
This will give your screen sessions two lines at the bottom of the screen - the first showing the open windows, the second showing a static message.
But what if you don't want to have those messages on the screen at all times? Well that's not a problem:
# # Toggle 'fullscreen' or not. # bind f eval "caption splitonly" "hardstatus ignore" bind F eval "caption always" "hardstatus alwayslastline"
With these lines in place "Ctrl-a f" will remove them, and "Ctrl-a F" will restore them.
The next neat thing to do is show the output of commands in one of the two lines, here we'll use the hardstatus area to show the output of uptime. There are two things you need to do for this to work:
We'll do this as follows:
backtick 1 5 5 uptime hardstatus alwayslastline "%1`"
Here we've defined a command with ID 1, which is valid for 5 seconds and should auto-refresh after 5 seconds. The command is uptime.
Additionally we've included %1` in format string for the relevant part of the display. This will be substituted with the output of the first command.
The important thing to notice is that the command we've chosen only outputs a single line of text - that must always be the case.
To complete our discussion of this area of GNU screen we should now mention some of the other facilities which are available to users who wish to customize their status bars.
The key to all customization is the use of format strings, strings which you'll enter in the display lines which will be replaced upon display. For example the following lines have extensive format strings:
#
# look and feel for the bottom two lines.
#
caption always "%{+b rk}%H%{gk} |%c %{yk}%d.%m.%Y | %72=Load: %l %{wk}"
hardstatus alwayslastline "%?%{yk}%-Lw%?%{wb}%n*%f %t%?(%u)%?%?%{yk}%+Lw%?"
Below is a brief summery of the options, copied almost entirely from "man screen". The escape character is '%' with one exception: inside a window's hardstatus line '^%' is used instead.
% the escape character itself
a either 'am' or 'pm'
A either 'AM' or 'PM'
c current time HH:MM in 24h format
C current time HH:MM in 12h format
d day number
D weekday name
f flags of the window
F sets %? to true if the window has the focus
h hardstatus of the window
H hostname of the system
l current load of the system
m month number
M month name
n window number
s seconds
t window title
u all other users on this window
w all window numbers and names. With '-' quailifier: up to the
current window; with '+' qualifier: starting with the window
W all window numbers and names except the current one
y last two digits of the year number
Y full year number
With that list there is plenty of scope for creating simple updates to the display. For example displaying the current date, time, and system load would be as simple as:
hardstatus alwayslastline "Host: %H Date: %D-%M-%Y: Load: %l "
If you'd like to experiment yourself there are many more format strings giving a lot of choice for customization (such as the use of colours). To see the full list run "man screen" and search for the section entitled STRING ESCAPES.
Cool. I have the following lines or something similar. I've no idea where I found them but they seems to work well enough for me.
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %d/%m %C%a "
caption always "%3n %t%? @%u%?%? [%h]%?"
--
"It's Not Magic, It's Work"
Adam
[ Parent ]
hardstatus off hardstatus string (%n.%t) termcapinfo xterm*|rxvt*|kterm*|Eterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'hardstatus off tells screen not to use the hardstatus line for messages, instead they'll be overlaid in reverse video at the bottom of the screen. The hardstatus string is fairly simple compared to other examples above. The real magic is the termcapinfo line, which makes screen put the hardstatus information in the title of the xterm it's in. PuTTY also supports these escapes.
[ Parent ]
bind f eval "hardstatus alwaysignore"
bind F eval "hardstatus alwayslastline"[ Parent ]
[ Parent ]