Skip to content

Commit

Permalink
demos: run scripts in a fixed environment and record with term-transc…
Browse files Browse the repository at this point in the history
…ript
  • Loading branch information
ilyagr committed Sep 10, 2023
1 parent 1f9bc60 commit 139c194
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions demos/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
[operation]
hostname = "jujube"
username = "jjfan"
[ui]
color="always"
paginate="never"
log-word-wrap=true # Need to set COLUMNS for this to work
EOF
}
32 changes: 32 additions & 0 deletions demos/run_script.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 139c194

Please sign in to comment.