From 139c1941c71a797b189e7526e6b68cb846e322e0 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Mon, 28 Aug 2023 20:57:26 -0700 Subject: [PATCH] demos: run scripts in a fixed environment and record with term-transcript --- demos/helpers.sh | 24 ++++++++++++++++++++++++ demos/run_script.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 demos/run_script.sh diff --git a/demos/helpers.sh b/demos/helpers.sh index a83b02033d..f6a83a7567 100644 --- a/demos/helpers.sh +++ b/demos/helpers.sh @@ -39,3 +39,27 @@ comment() { echo -e "\033[0;32m${indented}\033[0m" blank } + +git_config() { + cat <<'EOF' > "$1" +[color] +ui=always +EOF +} + +jj_config() { + cat <<'EOF' > "$1" +[user] +name = "JJ Fan" +email = "jjfan@example.com" + +[operation] +hostname = "jujube" +username = "jjfan" + +[ui] +color="always" +paginate="never" +log-word-wrap=true # Need to set COLUMNS for this to work +EOF +} diff --git a/demos/run_script.sh b/demos/run_script.sh new file mode 100755 index 0000000000..1324856cdf --- /dev/null +++ b/demos/run_script.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -euo pipefail +. "$(dirname "$0")"/helpers.sh + +which term-transcript > /dev/null || echo "\`term-transcipt\` must be installed with e.g. \`cargo binstall term-transcript-cli\`. See also https://github.com/slowli/term-transcript" +which convert > /dev/null || echo "\`convert\` from ImageMagik needs to be installed to create pngs. Only svgs will be created." >&2 + +echo "jj --version: (set PATH to change)" +jj --version + +JJ_CONFIG=$(mktemp --tmpdir jjconfig-XXXX.toml) +export JJ_CONFIG +jj_config "$JJ_CONFIG" + +GIT_CONFIG_GLOBAL=$(mktemp --tmpdir gitconfig-XXXX) +export GIT_CONFIG_GLOBAL +git_config "$GIT_CONFIG_GLOBAL" + +# Make `jj` wrap text as opposed to `term-transcript` +# Currently, 80 is the only value the tool supports when +# used as a CLI. +# https://github.com/slowli/term-transcript/issues/59 +COLUMNS=80 +export COLUMNS + +for script in "$@"; do + script_base="${script%.sh}" + script_base="${script_base#demo_}" + (bash "$script" || echo 'SCRIPT FAIL') 2>&1 | tee /dev/stderr | term-transcript capture --no-inputs --pure-svg --out "$script_base".svg "$script_base" + # Resize to 700 width and any height + which convert > /dev/null && convert -resize 700x10000 -colors 50 -background black "$script_base".svg "$script_base".png || true +done