Dustin Boswell - Brain Dumps about Computers, Programming, and Everything Else
dustwell.com About Me Past Academic Work Photo Album Links I Use
Articles by Me Subscribe: RSS
Oil ETFs leak money Yes/No proposition bets div, span, and CSS "display:" Pair programming + screen Dear VirginAmerica.com SSH keys in 2 easy steps "An hour" vs. "A hour" How to hash passwords Snapshotting with Rsync MacBook Pro Sharp Edge Fixing Your Flaky Internet How X-over-SSH works Drinking Distilled Water Politician != Decider Understanding iTunes files My Audi A4 Gas Mileage djb-dns installation Vim Cheat Sheet
How to use screen to pair program. April 2, 2010

Pair programming is a great way for 2 people to work together on the same code. Typically, it's done with the programmers sitting right next to each other. But what if they are in separate places, or they just don't want to accidentally touch elbows (ewww...)?

The UNIX screen command is typically used to run multiple terminal programs inside a single ssh session, and be able to disconnect/re-connect to the session without the programs noticing. It's an awesome utility, but you can also use it to let multiple people interact with the same terminal screen, and hence, allow multiple people to use the same editor at the same time.

First, I'm assuming both programmers have a user account on the same machine, and are already logged in (or ssh'd in) to the machine. (If the second programmer doesn't have an account, he can use the first programmer's account, and the steps below are the same.)

Enabling multi-user with screen

There are two ways to do this. One way is to do
chmod u+s /usr/bin/screen
first, and then make sure everyone's ~/.screenrc file contains:
multiuser on
acladd second_programmer_username
The other way is to just have
multiuser on
acladd root
But then the second programmer will need to do sudo screen instead of just screen in the steps below. (There are also more advanced security options.)

First Programmer: run screen

The first programmer starts his day by doing:
screen
Hit ENTER to dismiss the screen startup message. Then, go about your normal activities, such as running vim, or grep, or whatever.

Second Programmer: attach to his screen

The second user does the following:
[sudo] screen -rx first_programmer_username/
This attaches to the other user's active screen.

That's it! Now you should both be seing the same window and can both use their keyboard.

Problems with the Delete Button?

When ssh'ing from a terminal in Mac OSX I noticed that my delete button no longer worked. (ssh'ing from PuTTY in Windows didn't have this problem.) To fix this, do:
TERM=screen; screen
whereever you would normally do screen. Or, it's probably easier to just put
alias screen='TERM=screen; screen'
in your ~/.bashrc file.

Essential commands while inside screen

CommandPurpose
Ctrl-a ?Show the screen help menu
Ctrl-a dDettach from the screen (without killing it)
Ctrl-a cCreate another window inside the screen.
Ctrl-a <space>  Cycle to the next window.
Ctrl-a aAlternate to the previous window.
Ctrl-a [Enter "scroll mode" (use Up/Down arrows, then ESC to exit).

Other screen flags

Command-linePurpose
screen -lsList all the active screens I have on this machine.
screenStart a new screen session.
screen -xReattach to my pre-existing screen session.

blog comments powered by Disqus