Supercharge your bash demo with this simple script.
Showtime.sh is the original name of a script that I used to source
in
scripts that I used to demo a feature used in a presentation
git clone https://codeberg.org/inknos/showtime-sh.git
cd showtime-sh
./show examples/minimal
git clone https://codeberg.org/inknos/showtime-sh.git
cd showtime-sh
podman build -t showtime-sh .
podman run --rm -it -v $PWD/examples:/examples:Z showtime-sh examples/minimal
Container builds will come...
dnf copr enable -y nsella/showtime-sh
dnf install -y showtime-sh
The show
script provides a convenient way to run you demos.
The script always looks for a demo.sh
file inside the directory that
you are passing as a command optrion.
demo.sh
is the only file explicitely required but you can specify
other files that can be used by show
.
Inside each demo directory you can make use of clean.sh
,
offline.sh
and theme.sh
. None of these files are mandatory.
# $ tree examples/
# examples/
# ├── colors
# │ ├── demo.sh # mandatory
# │ └── theme.sh # optional but always sourced by `show`
# ├── full
# │ ├── clean.sh # optional and sourced only with --clean
# │ ├── demo.sh # mandatory
# │ └── offline.sh # optional and sourced only with --offline
# └── minimal
# └── demo.sh # mandatory
Basic run
./show examples/minimal
# Equivalent to
# bash -c 'source ./show; source./examples/minimal/demo.sh'
Run a demo skipping all wait times with -y
./show examples/minimal -y
# Equivalent to
# bash -c 'source ./show; GOON=true source examples/minimal/demo.sh'
Perform a dryrun of the demo. All commands will be printed but not executed
./show examples/minimal --dryrun
# Equivalent to
# bash -c 'source ./show; DRYRUN=true source examples/minimal/demo.sh
Run a script quietly
./show examples/minimal --quiet
# Equivalent to
# bash -c 'source ./show; QUIET=true source examples/minimal/demo.sh
Define run clean steps with --clean
. This will call and execute
examples/minimal/clean.sh
./show examples/minimal --clean
# Equivalent to
# bash -c 'source ./show; source examples/minimal/clean.sh'
Define and run offline setup for your demos with --offline
. This will
call and execute examples/minimal/offline.sh
./show examples/minimal --offline
# Equivalent to
# bash -c 'source ./show; source examples/minimal/clean.sh'
Export your code to a bash file with --export
. This way you can
transform your demo.sh
file to a convenient bash script or a writeup
ready to be published in your blog.
./show examples/minimal --export sh
./show examples/minimal --export md
# Equivalent to
# bash -c 'source ./show; EXPORT_FORMAT=sh source ./examples/mimimal/demo.sh'
# bash -c 'source ./show; EXPORT_FORMAT=md source ./examples/mimimal/demo.sh'
As said before, Showtime can be run equivalently by importing it at the
top of your files. As a matter of fact, this script was intially thought
to be run inside your demo, whether it's called demo.sh
or with any
other name.
Later, it became more convenient to just use it as a command that would
but you can still experiment with sourcing it and exploit its full power.
...
You can customize colors and symbols by creating a theme.sh
file in your demo directory. This file will be automatically loaded when your demo runs.
Run the color demo to see it in action
./run examples/colors
Create a theme.sh
file in the same directory as your demo:
#!/bin/bash
# Custom theme for your demo
# Base colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
BOLD='\033[1m'
DIM='\033[2m'
# Semantic color customization
export C_HEADER="$BLUE" # Header border color
export C_HEADER_TEXT="$WHITE$BOLD" # Header text color
export C_SUCCESS="$GREEN" # Success symbol color
export C_ERROR="$RED" # Error symbol color
export C_WARNING="$YELLOW" # Warning symbol color
export C_INFO="$CYAN" # Info symbol color
export C_COMMAND="$PURPLE" # Command prompt color
export C_COMMAND_TEXT="$WHITE" # Command text color
export C_TEXT="$CYAN" # Main text color
export C_BULLET="$BLUE" # Bullet symbol color
export C_INTERACTIVE="$PURPLE" # Interactive prompt color
export C_PROMPT="$DIM$BLUE" # "Press Enter" prompt color
export C_SEPARATOR="$DIM$BLUE" # Separator line color
# Custom symbols
export S_BULLET="▶" # Bullet symbol (default: ➤)
C_HEADER
- Header border linesC_HEADER_TEXT
- Header textC_SUCCESS
- Success messages (✓)C_ERROR
- Error messages (✗)C_WARNING
- Warning messages (⚠)C_INFO
- Info messages (ℹ)C_COMMAND
- Command prompt ($)C_COMMAND_TEXT
- Command textC_TEXT
- Main paragraph textC_BULLET
- Bullet symbol colorC_INTERACTIVE
- Interactive bash promptC_PROMPT
- "Press Enter to continue" textC_SEPARATOR
- Separator lines
S_BULLET
- Bullet symbol for paragraphs (default: ➤)
The theme system uses fallback values, so you only need to define the colors you want to change.
Run all tests with bats
bats --tap tests/*
- make skip header configurable
- make messages configurable by user
- fix history duplicating in bash
- make ^C timeout configurable
- make ^C trap optionally on or off