GNU Screen – How to Change Status Line Based on Hostname

colorsgnu-screen

I have a shared home directory that is automounted via NFS on all the UNIX servers I log in to. I would like to have a single .screenrc that (for example) puts the hostname in the hardstatus line in a different colour to indicate when I am logged on to production versus development; our hostnames are such that this can easily be done through the use of pattern matching.

Is there any way of putting conditional statements into .screenrc? A quick grep of the man page doesn't seem to reveal anything obvious.

EDIT:

To clarify, I already have a custom hard status line; I want to change some of the colouring/fields displayed based on the hostname that screen is invoked on. I already have something like this for my PS1, however I would rather do this in the screen status line as I jump off from these hosts to routers/switches, which don't allow me to do any prompt colourisation. This way, I can have one window for production, and one for development, with the colour of the screen status line telling me which one I am on at a glance.

Best Answer

I see two way to do this, the first one is to make a .screenrc file by host.
Like .screenrc_serverA, .screenrc_serverB, ...
In your shell startup script set SCREENRC to something like .screenrc_`hostname`
Of course you can use the source command of screen to include something like .screenrc_default in each custom .screenrc_… files so that they only contains a caption/hardstatus line and not the whole configuration each time.

The second way would be to execute commands like screen -X hardstatus lastline ... (using if tests to execute the command with different value for ... depending of the hostname) in your shell startup script. When you will log on the server, screen -X will do nothing because screen will not yet be launched, but each time you open a new windows in screen the hardstatus will be updated.

Of course the 1st solution is better because the second one will refresh the hardstatus line each time you opened a news windows which is probably useless as the hostname will not have changed.