]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/30_env/30_env.ax-io
30_env: Make sure the default environment is always set
[ax-zsh.git] / core / 30_env / 30_env.ax-io
index 6b101e3d4914de6537290e75d5c2459ecc6663c1..2a2c83982917c53821f50b53b8059a9c28af2ebd 100644 (file)
@@ -7,7 +7,7 @@ if [[ -z "$TZ" && -r "/etc/timezone" ]]; then
 fi
 
 # Validate temporary directory
-if [[ -z "$TMPDIR" ]]; then
+if [[ -z "$TMPDIR" || "$TMPDIR" = "/" ]]; then
        if [[ -n "$XDG_RUNTIME_DIR" && -w "$XDG_RUNTIME_DIR" ]]; then
                # The "runtime directory" is set for this user, good, so use
                # it silently as the "temporary directory", too:
@@ -27,9 +27,23 @@ if [[ -z "$TMPDIR" ]]; then
                unset user_tmpdir
        fi
 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
 if [[ ! -w "$TMPDIR" ]]; then
        echo "Warning: Temporary directory \"$TMPDIR\" is not writable!" >&2
 fi
+export TMPDIR
+
+# TMPDIR is the only one required to be set, but make sure that TMP, TEMP
+# and TEMPDIR are set to the same sane path name when already present in the
+# environment:
+[[ -n "$TMP" ]] && export TMP="$TMPDIR"
+[[ -n "$TEMP" ]] && export TEMP="$TMPDIR"
+[[ -n "$TEMPDIR" ]] && export TEMPDIR="$TMPDIR"
 
 # Setup XDG cache directory
 if [[ -z "$XDG_CACHE_HOME" ]]; then