]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/30_env/30_env.ax-io
30_env: Tweak TMPDIR handling, no longer bother with TMP
[ax-zsh.git] / core / 30_env / 30_env.ax-io
index 33a165b579015de01f45c6859a673ee757a86f22..87875402633f5563ea1f596cab2bdc09701117fe 100644 (file)
@@ -6,6 +6,22 @@ if [[ -z "$TZ" && -r "/etc/timezone" ]]; then
        TZ=$(<"/etc/timezone") export TZ
 fi
 
+# Validate temporary directory
+if [[ -z "$TMPDIR" ]]; then
+       echo "WARNING: \"TMPDIR\" is not set, using /tmp as default!" >&2
+       TMPDIR='/tmp/'
+fi
+if [[ ! -w "$TMPDIR" ]]; then
+       echo "WARNING: Temporary directory \"$TMPDIR\" is not writable!" >&2
+fi
+# Make sure TMPDIR ends in a slash (like on macOS by default): this makes its
+# usage a bit safer ...
+case "$TMPDIR" in
+       */) ;;
+       *)  TMPDIR="$TMPDIR/"
+esac
+export TMPDIR
+
 # Setup XDG cache directory
 if [[ -z "$XDG_CACHE_HOME" ]]; then
        XDG_CACHE_HOME="$LOCAL_HOME/.cache"