#!/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 "$@"