1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # 30_env.ax-io: Setup environment
5 if [[ -z "$TZ" && -r "/etc/timezone" ]]; then
6 TZ=$(<"/etc/timezone") export TZ
9 # Validate temporary directory
10 if [[ -z "$TMPDIR" ]]; then
11 if [[ -n "$XDG_RUNTIME_DIR" && -w "$XDG_RUNTIME_DIR" ]]; then
12 # The "runtime directory" is set for this user, good, so use
13 # it silently as the "temporary directory", too:
14 TMPDIR="$XDG_RUNTIME_DIR"
16 # Try to find a sane "temporary directory", but warn the user
17 # that this is a best guess only!
18 TMPDIR="$(dirname $(mktemp -ut tmp.XXXXXXXXXX))/"
19 [[ -z "$TMPDIR" || "$TMPDIR" = "/" ]] && TMPDIR="/tmp"
20 user_tmpdir="$TMPDIR$UID"
21 mkdir -p "$user_tmpdir" >/dev/null 2>&1
22 if [[ -w "$user_tmpdir" ]]; then
23 TMPDIR="$user_tmpdir/"
26 echo "Note: \"TMPDIR\" was not set, using \"$TMPDIR\"." >&2
30 if [[ ! -w "$TMPDIR" ]]; then
31 echo "Warning: Temporary directory \"$TMPDIR\" is not writable!" >&2
34 # Setup XDG cache directory
35 if [[ -z "$XDG_CACHE_HOME" ]]; then
36 XDG_CACHE_HOME="$LOCAL_HOME/.cache"
38 if [[ ! -d "$XDG_CACHE_HOME" ]]; then
39 mkdir -p "$XDG_CACHE_HOME"
40 chmod 0700 "$XDG_CACHE_HOME"
44 # Setup XDG runtime directory
45 if [[ -z "$XDG_RUNTIME_DIR" ]]; then
46 XDG_RUNTIME_DIR="$TMPDIR/runtime-dir.$UID"
48 if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
49 mkdir -p "$XDG_RUNTIME_DIR"
50 chmod 0700 "$XDG_RUNTIME_DIR"
52 export XDG_RUNTIME_DIR
54 # Setup ZSH cache directory
55 if [[ -z "$ZSH_CACHE_DIR" ]]; then
56 ZSH_CACHE_DIR="$XDG_CACHE_HOME/zsh"
58 if [[ ! -d "$ZSH_CACHE_DIR" ]]; then
59 mkdir -p "$ZSH_CACHE_DIR"
60 chmod 0700 "$ZSH_CACHE_DIR"