Recording all your terminal sessions
I love to log as much information as I can about what I do on my computer. (Of course, I never send those logs to third-party services.) I log all of my keystrokes, I religiously keep all of my command history, all of my email and IRC logs, and so on.
However, something that I didn't log so far is what appears in my terminals. This was a shame: since terminals display text, you would expect that you could log everything which appears on them without using up so much space after all. Logging this information could be useful to reconstitute what you were doing at a particular point in time, to understand how you ended up making a certain mistake or doing a certain thing, to show to someone how to do something, to recover the output of any particular command of your history, and so on.
There is a tool called ttyrec which can be used to log
what happens in your terminals (including timing information), but I didn't use
it systematically so far because of one simple issue: if you run cat
large_file
, then ttyrec will happily put all the content of
large_file
in its log, even though you probably didn't care about
it. Just a few accidents like this and your log files can become huge.
The point of this post is to advertise ttyrex, a slight modification of
ttyrec which adds an option to cap the quantity of data logged every second. The
point of this is that when doing cat large_file
, you can just log
a small quantity of the file every second and skip the rest, and you will get a
reasonable approximation of what you saw on the terminal without using up too
much space.
I have been starting ttyrex systematically with urxvt for some time now, compressing logs that are older than two weeks (this saves a tremendous amount of space), and the last two week's worth of logs use up a quantity of disk space which I think is reasonable by today's standards (less that 1 GB). I have also tweaked zsh to store the start time and stop time of the recorded sessions, the start time of ongoing sessions, and the command history of each session: I have then written a command to replay what happened at any point in time (i.e., open one replay terminal for each terminal that was open at some timestamp, and jump at the correct position in each of the replays), and a command to take a line of the command history and open a replay of the right session at the right time to see when the command was entered and which results it gave.
I haven't found any use for all of this yet except playing around, but it's pretty fun (having terminals which replay what I did in the past feels a lot like time travel).