How do I display the current "session" name or "sockname" of a screen session in the status bar?
I run multiple screen sessions each created with 'screen -S name' and I would like to be able to display in the st开发者_如何学JAVAatus bar the name I used to create the current screen session.
However, I cannot seem to accomplish this. Any ideas?
The easiest way to display the sessionname is
C-a :
sessionname
(without specifying a name after sessionname
)
See the "CUSTOMIZATION" section in man screen
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.
In current versions of screen
, there is a flag %S
for the hardstatus line.
MWE (.screenrc):
hardstatus on
hardstatus alwayslastline
hardstatus string "%S"
This displays the session name without the ID (like ${STY#*.}
).
(Same answer to other questions here and here for completeness).
paraphrased from https://superuser.com/a/212520/151988, put this into your ~/.screenrc;
screen
screen $SHELL -c 'screen -X caption always "$STY"'
Super User has an answer to this that does not require $STY
, instead using the backtick
screen config command and screen -ls
: https://superuser.com/a/212520
If nothing else works (as for me), as a workaround you can create a window with number 0 and set title to your screen name:
screen -S myscreen
C^a :title "myscreen"
As max_cantor says in the SuperUser Answer, an escape character for the session name should be added to version 4.1.0. It looks like the escape character function was added with a relatively small patch back in 2008. So if you're feeling brave, you can git yourself a copy of the development version 4.1.0 and try it out.
I'll try this with the development version when I get a chance.
"screen -X sessionname" i'm using ssh,i thought this is a straight answer , sessionname will show at the screen bottom
精彩评论