Last active
August 29, 2015 14:07
-
-
Save brimston3/663c5a7f9f8f129a5c6c to your computer and use it in GitHub Desktop.
Automatic screen session setup/reattach at login.
This file contains hidden or 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
if [ ! -z "$PS1" ] && [ -z "$STY" ] && which screen 2>&1 > /dev/null | |
then | |
old=$IFS | |
IFS=$'\n' | |
screens=($(screen -ls | egrep -iv '\(.*dead.*\)' | grep -e '(.*)' | awk '{print $1}')) | |
IFS=$old | |
if [ ${#screens[@]} -ge 1 ]; then | |
# pre-existing session, reattach to the first, leaving no bash parent behind. | |
exec screen -x "${screens[0]}" | |
else | |
# No existing session. | |
# run a particular background script in a window, then move it to window 99. | |
screen -q -d -S mon -m /home/tw/xinits/startx_xcmo | |
screen -p 0 -X number 99 | |
# start up a shell session so we have something to go to. | |
screen -X screen $SHELL | |
# reattach to the new shell session (window 0), leaving no bash parent behind. | |
exec screen -p 0 -x | |
fi | |
else | |
: # echo "Normal shell?" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
variant on autoscreen.bashrc written for use on my htpc.