#!/bin/bash # ~/.bashrc.d/screen # 2009-12-21 # bpkroth # # Auto launch screen on SSH connections # Sometimes a pain to deal with SSH screen sessions. # Can be done with C-a a* though. # Also a good idea to always use a hardstatus or caption line in .screenrc if [ $EUID != 0 ] && [[ $TERM != screen* ]] && bin_in_path screen; then if [ -n "$LC_CSSH" ]; then # This special variable was set to denote this # connection as a member of a CSSH session. Use the # value of the variable to select or create a screen # session with that name. if screen -list | grep "[0-9]\+\.$LC_CSSH[ ]*" > /dev/null; then screen -x $LC_CSSH else screen -S $LC_CSSH fi elif [ -n "$SSH_TTY" ]; then # This is a remote session. # Connect to the singular screen instance if it is # available, else list if there are multiple, else # start a new one. N=`screen -list | grep -c '[0-9].*tached'` if [ $N == 1 ]; then screen -x elif [ $N == 0 ]; then #exec screen # no, i want to be able to detach screen else echo screen -list fi #else # local connection, don't open a screen session # #exec screen # screen fi fi