6

Instead of recording my own keystrokes to create an asciinema tutorial I do want to script them, so I can easily improve my tutorial over time without being being stressed about redoing it each time I want to make a change, or spending a lot of time trying to correct typos in the recording.

Mainly I want to be able to do somethign like:

type: "df"
wait: 2s
type: "echo foo"

This would enable me to easily rebuild the recording from scratch when I change the script.

How can I do this?

sorin
  • 161,544
  • 178
  • 535
  • 806

4 Answers4

6

I've searched for a lot of solutions for my own projects, and this is the solution that I've come up with:

My solution:

What I'm planning on doing for a project I'm in is to use both asciinema as well as demo-magic.sh.

Specifically, I'll be using asciinema for the recording with the -c flag (see here), and demo-magic.sh for the automated typing, since it supports waiting for commands to finish executing (or not) and custom wait times on top of that. The command would look something like asciinema rec -c "./mydemoscript.sh" myrecording. See the projects for proper usage.

Other things I've come across:

doitlive -- I'm not using this because it's more of a fake-typing automated thing where you actually have to "type like a madman", which could be useful if you're doing a talk in front of an audience but you don't want to mess up your keystrokes, or if you don't want to forget to do certain commands.

asciiscript -- it's written in Go and it works, but you need to compile it yourself, and it also doesn't support waiting for the previous command to finish.

spielbash -- a Ruby project designed specifically to automate asciinema recordings using tmux. I'm not using this, though, because it's not as portable since you need an existing Ruby installation, and more importantly, it keeps corrupting the active console I'm in, and there's also unpredictable corruption in the recordings. Also, the project hasn't been committed to since 2019.

termscript -- it just doesn't work for me, and it freezes my console. It runs on python 2.


UPDATE: I have recently come across terminalizer. It seems to provide support for an window-like border around the actual terminal, and it has a built-in GIF renderer, but I have not tried it.

a-la-linuques
  • 71
  • 1
  • 5
1

There is a project svg-term which allows to record a screencast from a command, and I've seen a script that simulates commands being typed letter after letter.

Jan Warchoł
  • 1,063
  • 1
  • 9
  • 22
0

For the moment I ended up using AppleScript to automate iTerm but this approach is buggy and locks you to MacOS and iTerm... and if you happen do to something during recording, you are doomed.

I am still looking for a better approach.

sorin
  • 161,544
  • 178
  • 535
  • 806
0

TL;DR: asciinema-automation should do what OP wants. Its dependencies are asciinema and pexpect.

(disclaimer: I developed it for my own usage)

Some time ago, I was also looking for a way to automate asciinema recordings and I saw the very nice answer of a-la-linuques. I chose asciiscript because it used asciinema, but it is not maintained anymore. I tried to keep on using it via a fork adding new small features, but being not very familiar with go, I finally decided to rewrite everything in python in this repo.

It reads bash files, where comments can give special instruction like adding time between command or key stroke, or wait for an expected output (see examples). Of course, this is very much in the spirit of asciiscript.

Pierre Marchand
  • 619
  • 1
  • 7
  • 10