Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 54 lines (43 sloc) 1.08 KB
#!/bin/bash
# Lists all your current screen sessions and allows you to
# pick which one you want to join
# filters the screen -ls output to show the sesssions
sessions=`screen -ls | sed -n $SED_EXT 's/(\(Attached\)|\(Detached\))// p'`
res=`echo "$sessions" | wc -w | sed 's/^[[:space:]]*//'`
if [[ "$res" == "0" ]]
then
echo " No existing SCREEN session to reattach to..."
exit
fi
echo ''
echo " CURRENT SESSIONS"
echo " ------------------------"
echo "$sessions" | cat -n
echo " ------------------------"
echo ''
#if first argument is not specified, script will ask for number of screen
if [ -z $1 ]
then
echo -n " Reattach to session: "
read session
else
session=$1
fi
#attach to specified session
linenum=0
name=`screen -ls | sed -n $SED_EXT 's/(\(Attached\)|\(Detached\))// p' | sed $SED_EXT 's/[[:space:]]//' |
while read line
do
let "linenum += 1"
if [[ "$linenum" -eq "$session" ]]
then
echo $line
break
fi
done`
if [[ "$name" != "" ]]
then
screen -RUD "$name"
else
echo " Could not reattach to '$session'"
fi