ISO27001:2013
Certified Supplier

FIND OUT MORE

We're an ISO27001:2013 Certified Supplier

blog-post-featured-image

asciinema is a tool to record terminal sessions, which is quite useful for training, show and tell, or demonstrating how something works. It’s similar, but not identical to script, which we covered in a previous tip.

Installing aciinema is as simple as grabbing the package from your favourite package manager. For Debian-family systems:

apt install asciinema

From there, asciinema rec /path/to/file will start a capture which will record to the specified file. At the end of what you want to record, exit with Ctrl+D or by running exit. Then, on exit, there will be the option to upload the recording to asciinema.org. You can also run an asciinema-server to host your own API server, to hold and share your own recordings.

asciinema play /path/to/file will play back a recording, as does asciinema play https://example.com/path/to/recording; the only difference is where the recording is kept. Press the spacebar to pause or resume, and use . when paused to step through frame by frame.

As with script, asciinema will capture the prompt; one difference is that asciinema will capture the prompt as it’s set in your shell’s configuration. You may want to append a line to your .bashrc to set $PS1 to something shorter.

echo 'export PS1="Prompt: "' >> .bashrc

Once finished,  just remove the last line, either by hand or using a one-liner.

sed -i '$d' .bashrc

Alternatively, set $PS1 based on the value of $ASCIINEMA_REC, which is set to 1 when recording.

asciinema does also pay attention to keypress timings, so be aware of that when playing back! Ultimately, all of this is output as a json-formatted text file.

A nice extra with asciinema is the ability to export them to animated SVGs with svg-term. This means you can get really smooth, crisp animations usable where-ever you can view or embed a SVG file. Once installed from npm, just pipe a recording into it, or pull from an asciinema.org upload with --cast.

Photo by Noom Peerapong on Unsplash.

Leave a Reply

Your email address will not be published. Required fields are marked *