Last active
August 29, 2015 14:24
-
-
Save libcrack/eaac9fa27d2a019fa1c9 to your computer and use it in GitHub Desktop.
BSD flavoured (csh) auto-screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##[--------------- start csh auto-screen snippet ----------------] | |
# BSD flavour by borja@libcrack.so - 2015 | |
# Auto-screen invocation. see: http://taint.org/wk/RemoteLoginAutoScreen | |
# if we're coming from a remote SSH connection, in an interactive session | |
# then automatically put us into a screen(1) session. Only try once | |
# -- if $STARTED_SCREEN is set, don't try it again, to avoid looping | |
# if screen fails for some reason. | |
setenv STARTED_SCREEN | |
setenv DISPLAY | |
alias settitle printf '"\033]2;\!*\a\033]1;\!*\a\033]0;\!*\a"' | |
if ( "$TERM" != screen && $?prompt == 1 && "${STARTED_SCREEN}X" == X \ | |
&& "${SSH_TTY}X" != X && "${DISPLAY}X" == X ) then | |
echo "Auto-starting screen." | |
# Set the window title to HOSTNAME | |
settitle $user@$HOSTNAME : $cwd | |
# If no session is running, set DISPLAY environment variable | |
screen -ls | egrep -q "^No Sockets found" | |
if ( $? == 0 ) then | |
setenv | grep -q DISPLAY || setenv DISPLAY 0 | |
@ DISPLAY = $DISPLAY + 1 | |
setenv DISPLAY $DISPLAY | |
echo "No running screen found. DISPLAY set to $DISPLAY." | |
endif | |
sleep 3 | |
setenv STARTED_SCREEN 1 | |
screen -D -RR && exit 0 | |
# normally, execution of this rc script ends here... | |
echo "Screen failed! Continuing with normal bash startup." | |
endif | |
if ( "$STARTED_SCREEN"X == X && "${prompt}"X != X ) then | |
echo "Available screens:" | |
screen -ls | |
endif | |
##[------------------ end csh of auto-screen snippet ------------------] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment