Find that lost screen session: Episode 3.
Posted Mon, 07 Jul 2008
Today, I finally sat down and worked on the next installment: Being able to query any screen window and the window list. The difference between the previous script is that we can now grep screen windows other than the 0th one. Additionally, we can now grep the screen window list (which, by the way, has some excellent information).
To that end, I present now two scripts:
You need both for this to work optimally, but they exist separately because the functionality is somewhat distinct.The 'hardcopy' script takes a single argument, a screen session. It will hardcopy all windows in that screen session including the window list. If you specify OUTDIR in your environment, the screen hardcopies will be put in that directory; otherwise, the output directory is printed to stdout for consumption by another script.
The 'search' script runs the hardcopy script on all active screen sessions (in parallel, yay xargs). Once it has all of the copies, it will grep through the output for your query string (regular expression). It supports 3 flags:
- -t - only search 'window titles' (ie; only window list output)
- -w - only search window contents (ie; exclude window list output)
- -l - only search the 'location' field of the window list
Num Name Location Flags 0 zsh syn $ 1 zsh scorn $Now, I want to find all sessions open to 'scorn':
% screen-session-search.sh -t 'scorn' sty 18210.pts-8.snack window 1 sty 18556.pts-0.snack window 0It found 2 sessions. I can attach to the first one with:
screen -x 18210.pts-8.snack -p 1
^ screen session ^ window
caveat: I've been hacking on things all night, so the code may or may not be
very readable. Apologies if you go blind while trying to read it ;)