Created
March 2, 2012 22:18
-
-
Save memory/1961818 to your computer and use it in GitHub Desktop.
automatic screen creation/reconnection from .bash_profile
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
# a quick and dirty little hack: never get screwed by the fact that you forgot to | |
# run "screen" on a remote host ever again! | |
# | |
# put this into your .bash_profile at the very end, or in a separate file and source | |
# it (again as the last action) from .bash_profile. | |
if [ "$TERM" != "screen" ]; then | |
output=$(screen -ls | grep ached) | |
screens=($(echo "$output" | awk '{print $1}'|xargs)) | |
statuses=($(echo "$output" | awk '{print $2}'|xargs)) | |
numscr=${#screens[@]} | |
if [ ${numscr} -gt 0 ]; then | |
n=0 | |
echo | |
echo There are existing screen sessions: | |
echo | |
while [ $n -lt $numscr ]; do | |
echo "[$n] ${screens[$n]} ${statuses[$n]}" | |
n=$(($n+1)) | |
done | |
echo | |
read -p "Select an existing screen or hit enter to start a new one. " ANSWER | |
if [ -z "$ANSWER" ]; then | |
exec screen | |
else | |
exec screen -DDRR ${screens[$ANSWER]} | |
fi | |
else | |
exec screen | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment