-
Notifications
You must be signed in to change notification settings - Fork 41
/
screens
executable file
·53 lines (43 loc) · 1.08 KB
/
screens
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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