Making bash automatically attach screen when you login sounds cool. However, it's fraught with peril: what if screen breaks and you can't get a shell to fix it? What if screen gets attached when you preform operations like scp, or use the system system call?
update I've been using this for quite a while, and it hasn't caused me any problems yet.
setting it up
Here's the solution I'm devising for this.
Put the following in your .bashrc.
if [ `uname -n` = 'lefschetz' -a \ `expr index $- i` != 0 -a \ x"$SHLVL" = x1 -a \ ! -e dont_start_screen ]; then screen -x main fi
only start on the host lefschetz
- start only on interactive shells (helps not run on scp and stuff like that)
- only start on first-level shells, so if you type "bash" it won't start again. This also is another test for interactiveness.
if the file dont_start_screen exists, don't start it. This allows escaping from the
I start screen with -xU main, which you may want to change (main makes it try to attach the session named main, as given by the -S startup option.
fixing it if it breaks
If screen hangs, you have a problem. To make screen not start, this works:
ssh -t lefschetz bash
This makes it allocate a tty, but screen doesn't start because SHLVL is 2 since it's been invoked through another shell.