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:
- Write the command for you on the screen;
- Wait for you to press
- 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 . demo-magic.sh # Clear the screen before starting clear # Print and execute a simple command pe "echo 'hello world'" # Wait until the user presses enter wait # Print and execute immediately pei "bat my-demo.sh"
Save the script as a file named
my-demo.sh (well, any name, really) and just
bash my-demo.sh 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
- Personalize the prompt;
- Simulate network connections even if offline (whaaat);
- Run hidden commands, not shown to the public;
- Add timeouts to the
- Get help on your
my-demo.shscript using the
- Type your own commands, if needed, using the
asciinema is another gem worthy of its own blog post, because srsly. It’s so awesome I don’t know where to start. ↩︎