From 9af0edcad58ebde83147c3aab8ab7db0ad83e321 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Fri, 8 Dec 2023 17:43:06 +0100 Subject: [PATCH] 30_env: Make sure the default environment is always set Now the default environment is set up in non-login shells by including the "30_env.ax-io" code, too, if some of the standard variables are not set or invalid. --- core/30_env/30_env.ax-io | 16 +++++++++++++++- core/30_env/30_env.zshrc | 25 +++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/core/30_env/30_env.ax-io b/core/30_env/30_env.ax-io index 6b101e3..2a2c839 100644 --- a/core/30_env/30_env.ax-io +++ b/core/30_env/30_env.ax-io @@ -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 diff --git a/core/30_env/30_env.zshrc b/core/30_env/30_env.zshrc index 4187712..cac098a 100644 --- a/core/30_env/30_env.zshrc +++ b/core/30_env/30_env.zshrc @@ -1,17 +1,14 @@ # AX-ZSH: Alex' Modular ZSH Configuration # 30_env.ax-io: Setup environment -# 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 - -# 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" ]] && TMP="$TMPDIR" -[[ -n "$TEMP" ]] && TEMP="$TMPDIR" -[[ -n "$TEMPDIR" ]] && TEMPDIR="$TMPDIR" +if [[ + "$TMPDIR" = '/' || + -z "$TMPDIR" || + -z "$XDG_CACHE_HOME" || + -z "$XDG_RUNTIME_DIR" || + -z "$ZSH_CACHE_DIR" +]]; then + # Looks like the environment wasn't set up/exported properly! + [[ -n "$AXZSH_DEBUG" ]] && echo 'Note: Fixing up the environment!' + . "$AXZSH/core/30_env/30_env.ax-io" +fi -- 2.39.2