•

Recording & Sharing Terminal Sessions

By Kay Rhodes • 7 minute read •


This post describes how to make high quality recordings of terminal sessions that can be replayed in the terminal, or shared on the web. I’m defining high quality as recordings with zero typos, and relatively controlled timing between commands.

to see an example of the type of output I’m talking about.

Why? Videos and gifs take up a lot of disk space, don’t age well as display technology improves, and are problematic for folks low vision requirements.

With the techniques below you can not only share examples of usage on your web pages, but within your tools themselves.

Goal(s)

Bonus points:

Tools

Its a live (itsalive)

same core idea as “doitlive” BUT with some additional functionality like being able to spit out a whole line, and drive interactive things like vim.

source code (GitLab)

What It Does

problems

Notes

It will start playback in the default shell. If you want to specify a particular shell to playback with set the shell environment variable to the executable for that shell. E.g. SHELL=/opt/homebrew/opt/bash/bin/bash itsalive recording.sh

I keep my bash shell nice and minimal for recordings, but my day-to-day stuff is in fish.

doitlive

What it does

Problems

Notes

It will start playback in the default shell. If you want to specify a particular shell to playback with set the shell environment variable to the executable for that shell. E.g. SHELL=/opt/homebrew/opt/bash/bin/bash doitlive recording.sh

I keep my bash shell nice and minimal for recordings, but my day-to-day stuff is in fish.

script (unix command)

old unix command BSD version (macOS) and Linux version are different. Linux needs scriptreplay. macOS version you can just point the same tool at a file and say -p to “play” it back.

What it does

Problems

Asciinema

You can self-host (just needs the .js and .css files), or upload your recordings to Asciinema.org. Who knows how long Asciinema.org will continue to exist though.

What it does

Problems

Power-up Combo

how to make sweet looking recordings without typos or weird pauses.

  1. figure out exactly what commands you want to execute

  2. create a file itsalive (or doitlive) with those commands My recommendation is to use itsalive though because of the ability to record comments to yourself and the viewer.

    Note that it’s not going to be recording timings, or edits or anything like that. It just records the commands you enter, and the file is only those commands, so it’s really simple.

  3. add asciinema rec <filename> to the start of it so that it starts asciinema recording

  4. add a ##@pause comment in your script and then type ^d to exit asciinema without seeing the word exit typed out.

  5. launch itsalive myfile.sh or SHELL=/path/to/shell itsalive myfile.sh

  6. launch the presenter view in a separate terminal itsalive presenter_view

  7. click back into your original terminal but keep presenter view visible.

  8. Watch the presenter view not the real terminal. As you mash keys it’ll show you your progress against the characters in the line. This makes it trivial to hit CTRL+e at the right point to make it look like you pasted, or to quickly finish off long lines for any other reason.

  9. mash keys / hit return at appropriate times to move through the steps of the script

  10. Party.

    Now you’ve got a shell script for itsalive and an asciinema file to do with as you want. You probably don’t need the doitlive anymore, as it’ll likely produce different results when run months, or years, in the future, but maybe it’ll be useful to use as a starting point when you need to make a new recording for an updated version of the tool.

Real World Example

Here are the things I used to make some documentation for my git link-to-commit script.

What follows is the bash file that I ran with itsalive. Things of note:

Getting the timing right is still a bit of an art. The presenter_view really helped, but I needed to re-record a few times to get all the interactions and timings smooth enough. So, I just started the script off by having it delete any prior recordings (if present).

rm git-link-to-commit.asciinema 2>  /dev/null

## MOVE FAST AFTER THIS
asciinema rec git-link-to-commit.asciinema
git log -n1
# generate a link
## remember to mash then ^e when you get to the hash
git link-to-commit 2a15b8dea0ae606dedb8335e1c3106342e2d79ed
##@pause
##  ^r to RESUME playback
# skip the "choose a repo" step
## remember to mash then ^e when you get to the hash
git link-to-commit -o origin 2a15b8dea0ae606dedb8335e1c3106342e2d79ed
## EXIT ASCIINEMA
##@pause
## HIT ^d
## EXIT itsalive
exit

Demo

The final result.