tags:

views:

257

answers:

1

I run multiple screen sessions each created with 'screen -S name' and I would like to be able to display in the status bar the name I used to create the current screen session.

However, I cannot seem to accomplish this. Any ideas?

+2  A: 

screen has two status bars, the caption bar and the hardstatus bar, both of which use the string escapes specified in the "STRING ESCAPES" section of man screen. Unfortunately, there is no escape that directly refers to the session name.

However, there is a hack that will allow you to do this.

screen passes the session name to the shell using the $STY variable. When the shell attempt to set the window title (using one of these methods) screen captures that attempt, and stores it in something it confusingly calls "the window hardstatus," which does have an escape that you can use: %h.

So if you have either the caption or hardstatus bar set to include %h and have the shell attempt to set the window title to $STY, then the %h will be replaced with the session name when the bar is displayed.

rampion
Very close... Works great for the initial session however, once I am inside a screen session if I ssh to another host STY will no longer be set. Is there anyway to preserve that information or perhaps make screen only read the value once at the start of the session?
Neg_EV
@Neg_EV: Well, according to `man ssh`'s ENVIRONMENT section, if the sshd of the remote host allows it (default is not), you can set environment vars (like `STY`) in your local `.ssh/environment` file (so in your local `.bashrc`, just `cat STY=$STY > .ssh/environment`) and when you ssh to the remote machine that will set the appropriate environment vars.
rampion
@Neg_EV: If you don't want to (or can't) change the remote's `sshd` settings, then you could have your local `.bashrc` dump the STY value to a file, alias ssh to first scp that file to the remote host, and have your remote `.bashrc` source that file if STY is not set (that way the same .bashrc can be used remotely and locally).
rampion