Initial implementation

This is a bit of a lie, since I've been using this as a script for a while. But
now it's gotten long enough to warrant its own repo.