A collection of tools to create automated code demonstrations from simple bash scripts. These tools help you create polished, reproducible terminal demos for talks, videos, and documentation by scripting the commands and timing rather than recording live sessions.
cast2asciinemacreates an asciinema from your codecast2narrationcreates text-to-speech output from a screencast scriptcast2rstturns an asciinema asciicast into an RST markupcast2scriptconverts a cast to a scriptcast_livecreates a remote controlled terminal that can execute a code cast line-wisecast_bash.rccontains the bash configuration used by some cast helpers
xterm- Terminal emulator for running the demosxdotool- For simulating keyboard inputasciinema- For recording the terminal sessionscowsay- For cow sayin'
Clone this repository:
git clone https://github.com/datalad/screencaster.git
cd screencasterOptionally, add to your PATH to use from anywhere:
# Add to ~/.bashrc or ~/.zshrc
export PATH="$PATH:/full/path/to/screencaster"Then you can run cast2asciinema from any directory with your demo scripts.
demo.sh:
#!/bin/bash
say "Welcome to my demo"
sleep 1
say "Let's run some commands"
sleep 1
run "echo 'Hello, World!'"
run "ls -la"
sleep 2
say "That's all!"Make it executable and run it:
chmod +x demo.sh
# Assuming screencaster is in your PATH
# SCREENCAST_HOME avoids permission issues with default /demo directory
SCREENCAST_HOME=/tmp/demo cast2asciinema demo.sh outputThis will create output/demo.json. Play it with:
asciinema play output/demo.jsonTo convert your recording to an animated GIF, use Docker with the agg tool:
cd output
docker run --rm -v "$PWD:/data" kayvan/agg /data/demo.json /data/demo.gifThis creates an optimized GIF suitable for embedding in documentation or sharing.
You can upload recordings to asciinema.org for easy sharing:
asciinema upload output/demo.jsonThis returns a URL you can share. Asciinema.org also allows downloading recordings as GIF directly from their web interface.
say "text"- Display a comment in the terminal (auto-wrapped)run "command"- Type and execute a commandrun_expfail "command"- Run a command expected to failshow "text"- Display multi-line text as commentstype "text"- Type text without executingexecute- Press Enter and wait for command completionsleep N- Pause for N secondskey KeyName- Press a specific key (e.g.,key Return)
If your demo requires a Python virtual environment or other shell setup, activate it within the cast script using run:
#!/bin/bash
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Activate virtual environment in the demo terminal
run "source $SCRIPT_DIR/venv/bin/activate"
say "Now running commands with the activated environment..."
run "python --version"
run "pip list"Each run command executes in the same persistent shell session, so environment changes persist across commands.
By default, cast2asciinema tries to create a temporary home directory at /demo, which requires root access. To avoid permission issues, set the SCREENCAST_HOME environment variable to a writable location:
SCREENCAST_HOME=/tmp/demo cast2asciinema demo.sh outputThis directory is used as a clean, isolated environment for your demo and is cleaned up automatically after the recording completes.
If cast2asciinema fails with "Asciinema stopped unexpectedly", asciinema may be prompting for configuration (e.g., sharing settings). This can happen on first run or if settings are reset. The recording will fail during the prompt. Simply run the command again after responding to the prompt, and it will work correctly.
