blob: b6b592d4f0f8a340458e1b138dfc484572710a80 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
"$@"
|