End Point

News

Welcome to End Point's blog

Ongoing observations by End Point people.

GNU Screen: follow the leader

First of all, if you're not using GNU Screen, start now :).

Years ago, Jon and I spoke of submitting patches to implement some form of "follow the leader" (like the children's game, but with a work-specific purpose) in GNU Screen. This was around the time he was patching screen to raise the hard-coded limit of windows allowed within a given session, which might give an idea of how much screen gets used around here (a lot).

The basic idea was that sometimes we just want to "watch" a co-worker's process as they're working on something within a shared screen session. Of course, they're going to be switching between screen windows and if they forget to announce "I've switched to screen 13!" on the phone, then one might quickly become lost. What if the cooperative work session doesn't include a phone call at all?

To the rescue, Screen within Screen.

Accidentally arriving at one screen session within another screen session is a pretty common "problem" for new screen users. However, creative use of two (or more) levels of nested screen during a shared session allows for a "poor man's" follow the leader.

If the escape sequence of the outermost screen is changed to something other than the default, then the default escape sequence will pass through and take effect on the inner screen. In this way, anyone attached to the outermost screen will be following whomever is controlling the inner screen session as they flip between windows, grep logs, launch editors and save my vegan bacon! To "break away" from the co-working session, a user would simply use the chosen non-default escape sequence of the outermost screen to create a new window or disconnect entirely.

Sound confusing? Give some of the following commands a try. You can always just close out all the windows of a screen session and eventually you'll make it back to your original shell.

Steps:

  1. start the outermost screen session (called "followme") with a non-default escape sequence (pick one that suits you):
    screen -S followme -e ^ee
  2. from within the "followme" session, start the inner screen where actual work will be performed:
    screen -S work
  3. get friends and co-workers (logged-in as the same user) to connect to your "followme" screen:
    screen -x followme
  4. work as normal using the default: <CTRL> <a> sequences (which ought to affect the inner "work" session).
  5. to "break away" from the "work" session, use: <CTRL> <e> sequences (which ought to affect the outer "followme" session). For example, to disconnect from the shared session, one would type: <CTRL> <e> <d>

Note: If those sharing the screen session are already acclimated to screen-within-screen, you can skip the non-default escape sequences entirely and use <CTRL> <a> <a> as the escape sequence (another <a> for every level of screen-within-screen). This also happens to be your evasion route for accidental screen-within-screen moments.

Remember that, by default, everyone who wants to share the screen must already be logged-in as the same user (without the use of sudo or su). There are methods of allowing shared screen access between users, but those are outside the scope of this post.

Have fun!

edited on 09 OCT 2014 to update bacon link

2 comments:

Joe Clark said...

I found it helpful to disable all custom configuration of the parent/containing screen session with -c /dev/null, e.g.

screen -S followme -e ^ee -c /dev/null

This is necessary if you've overridden the default escape in your config file (the config file version takes precedence over the -e option version, which seems like a bug). It's at least helpful if you've configured your screen to have a status bar at the bottom.

Chris said...

Yo dawg, I heard you like screens...