I need it to determine if hitting ctrl+d would disconnect me from server or just close current screen
.
Is it somehow possible to check if I'm right now in screen
session?
I need it to determine if hitting ctrl+d would disconnect me from server or just close current screen
.
Is it somehow possible to check if I'm right now in screen
session?
You can look at the
$STY
variable (a variable set by the screen command). If it is not "" then you are in a screen session.I am in screen
I am not in screen
You can look at the $TERM variable.
echo $TERM
If it's a
screen
session, the term variable should return "screen".Ctrl-a -d (to exit screen)
Also check: https://stackoverflow.com/questions/3472287/how-do-you-tell-if-the-current-terminal-session-is-in-gnu-screen
Unless you have changed the default key bindings, you can do Ctrl+a -> Ctrl+t, which will show the time, if you are in screen. This will work even if you have ssh:d away somewhere else, unlike the other suggestions.
The
caption
command in the~/.screenrc
is a nice way to differentiate a screen session.I'm personally using this:
It adds a line like this one at the bottom of the screen:
With the first part (system name + load) in green and the date in pink. Useful and hard to miss!
I have found another solution:
Modify your
.screenrc
, so my screen session looks completely different from normal terminal.Better answer (in my opinion), inspired by this, just type the following:
If you get something like this:
… then you are in screen.
This is true not only for screen, but also for any kind of process (like script, nested bash or other shells) opening a nested shell, and this can even also show nested screen calls (if several not consecutive occurrences exists).
If you are looking at a command line prompt, you can just type something, anything, and hit Ctrl+A. If your cursor jumps to the beginning of the prompt, you're not inside a screen. If you additionally have to hit A, then you are.
Do a
screen -ls
. It's going to explicitly indicateAttached
versusDetached
status.Example attached:
Example detached:
to view your sessions and
to reconnect to a disconnected one, if detached.
to reconnect to a disconnected one.