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 8, 2023
1 parent 1f9bc60 commit 22673fa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
23 changes: 23 additions & 0 deletions demos/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,26 @@ 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"
EOF
}
25 changes: 25 additions & 0 deletions demos/run_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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"

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 --out "$script_base".svg "$script_base"
# Resize to 700 width and any height
which convert > /dev/null && convert -resize 700x10000 -colors 50 "$script_base".svg "$script_base".png || true
done

0 comments on commit 22673fa

Please sign in to comment.