Rewrite to modularise the 'record' command.

In general, this should be better, and make it easier to write
things such as 'replay'. However, it does mean that we have
to inject things into the environment through 'export' statements
rather than directly controlling the environment at startup.
Fix prompt command.