From: Alexander Barton Date: Tue, 24 Nov 2020 11:54:21 +0000 (+0100) Subject: 30_env: Tweak TMPDIR handling, no longer bother with TMP X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ax-zsh.git;a=commitdiff_plain;h=af5a9fffe4a374495cba3c4854c7e21e66ec85a7 30_env: Tweak TMPDIR handling, no longer bother with TMP Move the whole 30_env plugin logic to the "ax-io" stage, so that all other plugins in all stages can depend on it. And make sure that TMPDIR ... - is set and writable; show a warning message if not; - always ends with a "/", which makes its usage a bit safer. --- diff --git a/README.md b/README.md index 3ddbd0c..8e059fc 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Validated and/or set up by core plugins: * `PS1` * `SHORT_HOST` * `TERM` -* `XDG_RUNTIME_DIR` +* `TMPDIR` (set and always ends with a "/") * `XDG_CACHE_HOME` +* `XDG_RUNTIME_DIR` * `ZSH_CACHE_DIR` diff --git a/core/30_env/30_env.ax-io b/core/30_env/30_env.ax-io index 33a165b..8787540 100644 --- a/core/30_env/30_env.ax-io +++ b/core/30_env/30_env.ax-io @@ -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" diff --git a/core/30_env/30_env.zshrc b/core/30_env/30_env.zshrc deleted file mode 100644 index b8ee833..0000000 --- a/core/30_env/30_env.zshrc +++ /dev/null @@ -1,13 +0,0 @@ -# AX-ZSH: Alex' Modular ZSH Configuration -# 30_env.zshrc: Setup environment - -# Setup TMPDIR. Try to reset TMPDIR (when it is not set but TMP is), which is -# common in tools like screen(1) because Linux removes some varibes for -# "setgit" tools (see ). -# And therefore this has to be checked here, because inside of screen probably -# no login shell is started ... -[[ -z "$TMPDIR" && -n "$TMP" ]] && TMPDIR="$TMP" - -# Make sure TMP and TMPDIR become exported when they are set: -[[ -n "$TMP" ]] && export TMP -[[ -n "$TMPDIR" ]] && export TMPDIR diff --git a/plugins/calendar/calendar.ax-io b/plugins/calendar/calendar.ax-io index 1013200..53040a6 100644 --- a/plugins/calendar/calendar.ax-io +++ b/plugins/calendar/calendar.ax-io @@ -14,7 +14,7 @@ # don't show them now but return. [[ -z `find "$XDG_CACHE_HOME/axzsh_last_calendar" -mmin -60 2>/dev/null` ]] || return 0 -tmpfile=$(mktemp ${TMPDIR:-/tmp}/calendar.XXXXXX) || return 1 +tmpfile=$(mktemp "$TMPDIR/calendar.XXXXXX") || return 1 calendar -A0 >"$tmpfile" if [[ -s "$tmpfile" ]]; then diff --git a/plugins/icalbuddy/icalbuddy.ax-io b/plugins/icalbuddy/icalbuddy.ax-io index 7c6c6c3..c91ed76 100644 --- a/plugins/icalbuddy/icalbuddy.ax-io +++ b/plugins/icalbuddy/icalbuddy.ax-io @@ -14,7 +14,7 @@ # don't show them now but return. [[ -z `find "$XDG_CACHE_HOME/axzsh_last_reminder" -mmin -60 2>/dev/null` ]] || return 0 -tmpfile=$(mktemp ${TMPDIR:-/tmp}/icalbuddy.XXXXXX) || return 1 +tmpfile=$(mktemp "$TMPDIR/icalbuddy.XXXXXX") || return 1 if [[ "$LANG" =~ "\.UTF" ]]; then bul="•"; bul_imp="!"; sep="»"