Find that lost screen session
Posted Thu, 05 Jun 2008
(*) All my xterms run with: 'xterm -e screen -RR'. This causes them to attach to the first-found detached screen, and if none exist creates a new screen session. See run-xterm.sh for my pleasant, random-colored xterm script.
Problem: I forget where I put things. I can't find that terminal where I'm editing foo.c!
- Bad: Kill the vim session that's editing the file, and rerun vim somewhere else.
- Good: Use xdotool to search window titles for 'foo.c'
- Great: Find the screen STY variable for the process 'vim foo.c'
- Great: Ask each open screen session about what it is on screen
- Find a screen by it's child processes
This tool takes a regexp pattern as the only argument and will output a list of screen sessions having child process commands that match that pattern. This is useful for finding what screen is running 'vim foo.c'
% ./screenps.sh 'vim foo.c' 23464.pts-0.snack
- Find a screen by what is being displayed
This tool takes a regexp pattern as the only argument. It uses screen's hardcopy command to save the on-screen buffer and then applies the regexp given to the buffer. If it matches, the screen session is output. There is special behavior if only one screen session is found: If the screen session is currently attached, it will flash that screen session giving you a visual clue about where it is; if it is not attached, it will attach to it.
% ./screen-find.sh "keynav" 28504.pts-27.snack
A short summary: screenps.sh will search for commands running in a screen session and screen-find.sh will search for literal text displayed in a screen session. Both are super useful.
Note: Currently, screen-find.sh can only capture the contents of the 0th screen window (screen sessions can have multiple windows). I worked for a while on solving this, but for whatever reason I couldn't get it working properly.