My favorites | Sign in
Project Logo
                
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
# screen finder... thing.
#
# Greps the current screen of each current screen session for text.
# If only one match is found, then it will do one of two things:
# 1) If the screen is already attached somewhere, then we will make that screen
# blink so you see it.
# 2) If the screen is detached, then we will attach now.
#
# If multiple are found, each screen session name is output.
#
# Usage:
# ./sfind.sh <pattern>

windowcat() {
tmp=`mktemp`
STY=$1 screen -X hardcopy $tmp
cat $tmp
rm $tmp
}

screenlist() {
screen -ls | grep '^ ' | awk '{print $1}'
}

findscreen() {
for other in `screenlist`; do
# Only check screens that are not the current screen
if [ "$STY" != "$other" ] ; then
if windowcat $other | egrep -q "$1" ; then
echo $other
fi
fi
done
}

activate() {
s=$1
status=`screen -ls $s | grep $s | tr -d '()' | awk '{print $NF}'`

case $status in
Attached)
echo "$s"
for blink in 1 2 3 4 5; do
STY="$s" screen -X select -
sleep .05
STY=$s screen -X select 0
sleep .05
done
;;
Detached)
screen -x $s
;;
*)
echo "Unknown status $status on screen $s"
;;
esac
}

ACTIVATE=1
if [ "$1" = "-n" ] ; then
ACTIVATE=0;
shift
fi
screens=`findscreen "$@"`

found=`echo -n "$screens" | wc -w`

case $found in
0) echo "None found." ;;
1)
[ "$ACTIVATE" -eq 1 ] && activate $screens
echo "$screens"
;;
*)
echo "Multiple found:"
echo "$screens"
esac
Show details Hide details

Change log

r1916 by jordansissel on Jun 05, 2008   Diff
Add -n option to not blink the window
Go to: 
Project members, sign in to write a code review

Older revisions

r1911 by jordansissel on Jun 05, 2008   Diff
- run-xterm.sh: clean up some code
- screen-find.sh: echo the found
screen session if blinking it.
r1910 by jordansissel on Jun 05, 2008   Diff
- use egrep
r1907 by jordansissel on Jun 04, 2008   Diff
rename sfind.sh -> screen-find.sh
All revisions of this file

File info

Size: 1549 bytes, 78 lines
Hosted by Google Code