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" || "$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 # Make sure TMPDIR ends in a slash (like on macOS by default): this makes its
31 # usage a bit safer ...
36 if [[ ! -w "$TMPDIR" ]]; then
37 echo "Warning: Temporary directory \"$TMPDIR\" is not writable!" >&2
41 # TMPDIR is the only one required to be set, but make sure that TMP, TEMP
42 # and TEMPDIR are set to the same sane path name when already present in the
44 [[ -n "$TMP" ]] && export TMP="$TMPDIR"
45 [[ -n "$TEMP" ]] && export TEMP="$TMPDIR"
46 [[ -n "$TEMPDIR" ]] && export TEMPDIR="$TMPDIR"
48 # Setup XDG cache directory
49 if [[ -z "$XDG_CACHE_HOME" ]]; then
50 XDG_CACHE_HOME="$LOCAL_HOME/.cache"
52 if [[ ! -d "$XDG_CACHE_HOME" ]]; then
53 mkdir -p "$XDG_CACHE_HOME"
54 chmod 0700 "$XDG_CACHE_HOME"
58 # Setup XDG runtime directory
59 if [[ -z "$XDG_RUNTIME_DIR" ]]; then
60 XDG_RUNTIME_DIR="$TMPDIR/runtime-dir.$UID"
62 if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
63 mkdir -p "$XDG_RUNTIME_DIR"
64 chmod 0700 "$XDG_RUNTIME_DIR"
66 export XDG_RUNTIME_DIR
68 # Setup ZSH cache directory
69 if [[ -z "$ZSH_CACHE_DIR" ]]; then
70 ZSH_CACHE_DIR="$XDG_CACHE_HOME/zsh"
72 if [[ ! -d "$ZSH_CACHE_DIR" ]]; then
73 mkdir -p "$ZSH_CACHE_DIR"
74 chmod 0700 "$ZSH_CACHE_DIR"