diff options
Diffstat (limited to 'scripts/tui-sandbox.sh')
| -rwxr-xr-x | scripts/tui-sandbox.sh | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/tui-sandbox.sh b/scripts/tui-sandbox.sh new file mode 100755 index 0000000..b6b592d --- /dev/null +++ b/scripts/tui-sandbox.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Run a command with isolated bokftui config/cache for pty smoke tests, so a +# test can never clobber the real ~/.config/bokf/tui.conf or +# ~/.cache/bokf/tui.log. +# +# scripts/tui-sandbox.sh [--keep] -- command [args...] +# +# XDG_CONFIG_HOME and XDG_CACHE_HOME point at a fresh temp dir (printed on +# stderr). The dir is removed on exit unless --keep is given. +set -eu + +keep=0 +if [ "${1:-}" = "--keep" ]; then + keep=1 + shift +fi +if [ "${1:-}" = "--" ]; then + shift +fi +if [ "$#" -eq 0 ]; then + echo "usage: scripts/tui-sandbox.sh [--keep] -- command [args...]" >&2 + exit 2 +fi + +dir=$(mktemp -d "${TMPDIR:-/tmp}/bokf-tui-XXXXXX") +mkdir -p "$dir/config" "$dir/cache" +export XDG_CONFIG_HOME="$dir/config" +export XDG_CACHE_HOME="$dir/cache" + +cleanup() { + [ "$keep" -eq 1 ] || rm -rf "$dir" +} +trap cleanup EXIT INT TERM + +echo "tui-sandbox: config=$dir/config cache=$dir/cache" >&2 +"$@" |
