I am trying to launch GNU Screen using my .bashrc
. I'm almost there:
if [ -z "$STY" ]; then
exec screen -dR
else
exec gnome-terminal
fi
This is wrong though! The first case works, screen
launches when I open a terminal. But the second part fails. I want to open a regular terminal if I already have one open. But this just opens an infinite number of terminals...
You could try (after the else):
If I'm not mistaken, the terminal would open normally if you just remove the "else" block... Or maybe I'm missing something.
The way I have things set up I launch screen on every server I connect to if it has screen. When I disconnect and reconnect, the same screen session is reconnected. Sounds good so far, that's what everyone wants. But, if you have several windows open in screen, how do you disconnect without closing them? There are 2 options:
.screenrc
.bashrc
.bash_logout
The scripts above work on both Linux and Mac OS X (which is the reason you see "2>/dev/null ||" in the stat, touch, and date commands). I also use a 256 color xterm and I believe all the supporting code is included here. Despite the length of this post, I have trim a lot out of the scripts/configs.
Just type:
Notice that there is no
exec
and thatelse
is not needed. You can then simply typeexit
to get back to a regular terminal.Using
-ARR
has the added benefit that it will always resume the first appropriate detached screen session, if there is one. Otherwise, it will create a new one, which is what you are trying to achieve.Source: Screen man page