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.
Note that screen
is a terminal emulator. So your question is a bit like asking how can I start xterm
from gnome-terminal
and have what was last displayed in xterm
visible in my gnome-terminal
when xterm
exits.
Now the difference between xterm
and screen
is that while xterm
uses the X protocol to draw its screen, screen
uses a host terminal.
By default, screen
will clear the screen of its host terminal to display its own emulated terminal and where available will use the alternate screen (before clearing) of that host terminal, so that upon termination, it can restore the host terminal state as it was before starting.
So what you see is not screen
clearing the screen upon leaving, but restoring the host terminal's main screen. The content of the screen
window that was last displayed is still there on the alternate screen. With xterm
, you can have a look at it by selecting Show alternate screen in the Ctrl+MiddleClick menu.
If the host terminal doesn't support an alternate screen (like vt102 ones), it obviously can't do that. Instead, it does nothing, which is basically what you want.
So, what you can do is tell screen
that the host terminal doesn't support an alternate screen. For that, you can add to ~/.screenrc
:
termcapinfo * ti=:te=
Which says: for all possible host terminals (*
, matched against $TERM
), override the termcap/terminfo
database to say that for those terminals, the escape sequences to enter or leave the alternate screen are the empty string.
ti
and te
do not exactly mean alternate screen. From https://www.gnu.org/software/termutils/manual/termcap-1.3/html_node/termcap_39.html:
ti
(smcup
in terminfo
)
String of commands to put the terminal into whatever special modes are needed or appropriate for programs that move the cursor nonsequentially around the screen. Programs that use termcap to do full-screen display should output this string when they start up.
te
(rmcup
in terminfo
)
String of commands to undo what is done by the ti
string. Programs that output the `ti' string on entry should output this string when they exit.
But that translates to the alternate screen for most terminal emulators (specically, in xterm
it's alternate screen and saving/restoring of the cursor position)
Best Answer
It's a apparently a known bug: No characters beyond the BMP are displayed, as screen apparently only has a two byte buffer for characters.
(It works in tmux).