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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh

JOBS=${JOBS:-10}
OUTDIR=${OUTDIR:-$(mktemp -d)}
if [ -z "$OUTDIR" -o ! -d "$OUTDIR" ] ; then
echo "mktemp -d failed or \$OUTDIR is not a directory."
fi
export OUTDIR


screenlist() {
screen -ls | awk '/^[\t ]/ {print $1}'
}

capture_all() {
if [ "$(ls $OUTDIR | wc -l)" -gt 0 ] ; then
return
fi

screenlist \
| egrep -v SCREENTMP \
| xargs -n1 -P${JOBS} sh -c 'screen-session-hardcopy.sh $1 2> /dev/null' -
}

screen_processes_grep() {
if [ ! -f "/proc/$$/cmdline" ] ; then
echo "This tool requires procfs (freebsd or linux)."
exit 1
fi

for proc in /proc/[0-9]* ; do
pid=${proc#/proc/}
if [ "$pid" -ne "$$" -a -r $proc/environ ] ; then
if xargs -0 < $proc/cmdline | grep -q "$@" ; then
xargs -n1 -0 < $proc/environ | sed -ne 's/\(STY\|WINDOW\)=//p'
fi | paste -d ' ' - -
fi
done
}

search() {
capture_all
query=$1
files="$2"
shift; shift;

case $query in
location|title) files="$(ls $OUTDIR/*:windowlist)" ;;
windowcontents) files="$(ls $OUTDIR/ | grep -v ':windowlist$')" ;;
esac

MATCHES="$(cd $OUTDIR; grep -l "$@" $files)"

for M in $MATCHES ; do
fsty=$(echo $(basename $M) | awk -F: '{print $1}')
fwin=$(echo $(basename $M) | awk -F: '{print $2}')
if [ "$fwin" = "windowlist" ] ; then
if [ "$query" = "location" ] ; then
fwin="$(awk 'NF > 1 { print $1, $(NF - 1) }' $M \
| grep "$@" | awk '{print $1}')"
else
fwin="$(egrep "$@" $M | awk '{ print $1 }')"
fi
fi

if [ ! -z "$fsty" -a ! -z "$fwin" ] ; then
echo "$fsty $fwin"
fi
done
}


SEARCH=""

eval set -- `getopt -s sh twlc "$@"`
while [ $# -gt 0 ]; do
case $1 in
-t) SEARCH="${SEARCH} title" ;;
-w) SEARCH="${SEARCH} windowcontents" ;;
-l) SEARCH="${SEARCH} location" ;;
-c) SEARCH="${SEARCH} cmdline" ;;
--) break ;;
esac
shift;
done

[ -z "$SEARCH" ] && SEARCH="title windowcontents location cmdline"

for QUERY in $SEARCH; do
case $QUERY in
cmdline) screen_processes_grep "$@" ;;
windowcontents|location|title) search $QUERY "$@" ;;
esac
done \
| sort | uniq | grep -v "$STY $WINDOW"
# the previous grep is to remove our screen and window from the output list

# Clean up
rm -r "$OUTDIR"
rm -f /tmp/log.*
Show details Hide details

Change log

r2022 by jordansissel on Oct 08, 2008   Diff
screen-activate:
- small refactor of option parsing. Reads
from stdin now if no args given.
- Will try to activate a client using wmii
commands if $WMII_ADDRESS is found
- Will now select the window given as
argument 2
screen-session-hardcopy:
- Change windowlist output file to
:windowlist instead of :p
- Check if 'stat -x' works and use it if
available (FreeBSD)
...
Go to: 
Project members, sign in to write a code review

Older revisions

r1953 by jordansissel on Jul 07, 2008   Diff
- Fix bug when all content is scanned
(use find instead of ls)
- Change output to be more script and
human friendly.
r1951 by jordansissel on Jul 07, 2008   Diff
- Make debug logging optional
r1950 by jordansissel on Jul 07, 2008   Diff
- Make a SLEEP variable so I can tweak
the sleep delays globally.
- Call egrep when necessary
- Added proper option parsing
- New search abilities:
...
All revisions of this file

File info

Size: 2290 bytes, 100 lines

File properties

svn:executable
*
Hosted by Google Code