]> arthur.barton.de Git - ax-zsh.git/blob - core/30_env/30_env.ax-io
30_env.ax-io: Try to use a user-specific subfolder when TMPDIR is not set
[ax-zsh.git] / core / 30_env / 30_env.ax-io
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # 30_env.ax-io: Setup environment
3
4 # Setup time zone
5 if [[ -z "$TZ" && -r "/etc/timezone" ]]; then
6         TZ=$(<"/etc/timezone") export TZ
7 fi
8
9 # Validate temporary directory
10 if [[ -z "$TMPDIR" ]]; then
11         TMPDIR="$(dirname $(mktemp -ut tmp.XXXXXXXXXX))/"
12         user_tmpdir="$TMPDIR$UID"
13         mkdir -p "$user_tmpdir" >/dev/null 2>&1
14         if [[ -w "$user_tmpdir" ]]; then
15                 TMPDIR="$user_tmpdir/"
16                 chmod 0700 "$TMPDIR"
17         fi
18         echo "WARNING: \"TMPDIR\" is not set, using \"$TMPDIR\" as default!" >&2
19         unset user_tmpdir
20 fi
21 if [[ ! -w "$TMPDIR" ]]; then
22         echo "WARNING: Temporary directory \"$TMPDIR\" is not writable!" >&2
23 fi
24
25 # Setup XDG cache directory
26 if [[ -z "$XDG_CACHE_HOME" ]]; then
27         XDG_CACHE_HOME="$LOCAL_HOME/.cache"
28 fi
29 if [[ ! -d "$XDG_CACHE_HOME" ]]; then
30         mkdir -p "$XDG_CACHE_HOME"
31         chmod 0700 "$XDG_CACHE_HOME"
32 fi
33 export XDG_CACHE_HOME
34
35 # Setup XDG runtime directory
36 if [[ -z "$XDG_RUNTIME_DIR" ]]; then
37         XDG_RUNTIME_DIR="$TMPDIR/runtime-dir.$UID"
38 fi
39 if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
40         mkdir -p "$XDG_RUNTIME_DIR"
41         chmod 0700 "$XDG_RUNTIME_DIR"
42 fi
43 export XDG_RUNTIME_DIR
44
45 # Setup ZSH cache directory
46 if [[ -z "$ZSH_CACHE_DIR" ]]; then
47         ZSH_CACHE_DIR="$XDG_CACHE_HOME/zsh"
48 fi
49 if [[ ! -d "$ZSH_CACHE_DIR" ]]; then
50         mkdir -p "$ZSH_CACHE_DIR"
51         chmod 0700 "$ZSH_CACHE_DIR"
52 fi
53 export ZSH_CACHE_DIR