blob: aad0822877424325f9a8389573abfdc6e0c94728 (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/bin/sh
help() { echo "envrun - run programs in an isolated home directory
USAGE:
envrun [OPTION]... COMMAND
OPTIONS:
-d ENVHOME use the ENVHOME environment directory
-h show this help message"; }
while getopts 'd:h' o; do case "$o" in
d) export ENVHOME="$OPTARG" ;;
*) help >&2; exit ;;
esac done
shift $((OPTIND - 1))
export HOME="${ENVHOME:-"$PWD"}"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"
ensure_dirs() {
for dir in "$@"; do
[ -d "$dir" ] || { missing=1; break; }
done
[ "$missing" = 1 ] || return
printf "\nFollowing directories will be created.\n\n"
for dir in "$@"; do
[ -d "$dir" ] || echo "$dir/"
done
printf "\ncontinue? [y/N] "
read -r ans
case "$ans" in
y|Y) echo; mkdir -pv "$@"; echo ;;
*) exit ;;
esac
}
ensure_dirs \
"$XDG_CACHE_HOME" \
"$XDG_CONFIG_HOME" \
"$XDG_DATA_HOME" \
"$XDG_STATE_HOME"
[ "$#" -lt 1 ] && {
echo "Please provide a command to run."
exit
}
"$@"
|