]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/30_env/30_env.ax-io
30_env.ax-io: Create individual XDG_RUNTIME_DIR, when not set
[ax-zsh.git] / core / 30_env / 30_env.ax-io
index 33a165b579015de01f45c6859a673ee757a86f22..1910bd412665984da635a493a8cf57abf8f5dc6d 100644 (file)
@@ -6,6 +6,15 @@ if [[ -z "$TZ" && -r "/etc/timezone" ]]; then
        TZ=$(<"/etc/timezone") export TZ
 fi
 
+# Validate temporary directory
+if [[ -z "$TMPDIR" ]]; then
+       TMPDIR="$(dirname $(mktemp -ut tmp.XXXXXXXXXX))/"
+       echo "WARNING: \"TMPDIR\" is not set, using \"$TMPDIR\" as default!" >&2
+fi
+if [[ ! -w "$TMPDIR" ]]; then
+       echo "WARNING: Temporary directory \"$TMPDIR\" is not writable!" >&2
+fi
+
 # Setup XDG cache directory
 if [[ -z "$XDG_CACHE_HOME" ]]; then
        XDG_CACHE_HOME="$LOCAL_HOME/.cache"
@@ -18,7 +27,7 @@ export XDG_CACHE_HOME
 
 # Setup XDG runtime directory
 if [[ -z "$XDG_RUNTIME_DIR" ]]; then
-       XDG_RUNTIME_DIR="${TMPDIR:-/tmp/${UID}-runtime-dir}"
+       XDG_RUNTIME_DIR="$TMPDIR/runtime-dir.$UID"
 fi
 if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
        mkdir -p "$XDG_RUNTIME_DIR"