How to Use Demo Magic

My colleague Tobru recently pointed me to demo-magic, and I now seriously wonder how could I ever do a live demo without this. The description of the project says it all:

A handy shell script that enables you to write repeatable demos in a bash environment.

The idea is as simple as this: instead of having to type commands while doing demos or recording videos, just create a script that will:

  1. Write the command for you on the screen;
  2. Wait for you to press <ENTER>;
  3. Execute the command live for you.

And not only that, but it’s written in 100% shell script: just save the file locally, and make sure you have pv installed (sudo apt install pv should do the trick on Debian, Ubuntu and similar.)

Then write a script as follows:

#!/usr/bin/env bash

# Include the magic

# Clear the screen before starting

# Print and execute a simple command
pe "echo 'hello world'"

# Wait until the user presses enter

# Print and execute immediately
pei "bat"

Save the script as a file named (well, any name, really) and just bash to get started. Press <ENTER> to print the command, and press it again to execute it. As simple as possible, and very useful when demoing stuff on a terminal.

But you can do much more with

Simply put, this is a godsend for all the DevRel people reading this. Couple it with asciinema1 and you’re in for a treat.

Update, 2022–11-26: The movie in this page is embedded using the cljoly/gohugo-asciinema Hugo module created by Clément Joly.

Update, 2024-03-22: A similar tool, but generating animated GIF files instead, aptly named VHS.

  1. asciinema is another gem worthy of its own blog post, because srsly. It’s so awesome I don’t know where to start. ↩︎