Skip to content

Instantly share code, notes, and snippets.

@brimston3
Last active August 29, 2015 14:07
Show Gist options
  • Save brimston3/663c5a7f9f8f129a5c6c to your computer and use it in GitHub Desktop.
Save brimston3/663c5a7f9f8f129a5c6c to your computer and use it in GitHub Desktop.
Automatic screen session setup/reattach at login.
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
@brimston3
Copy link
Author

variant on autoscreen.bashrc written for use on my htpc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment