]> arthur.barton.de Git - ax-zsh.git/commitdiff
30_env: Tweak TMPDIR handling, no longer bother with TMP
authorAlexander Barton <alex@barton.de>
Tue, 24 Nov 2020 11:54:21 +0000 (12:54 +0100)
committerAlexander Barton <alex@barton.de>
Tue, 24 Nov 2020 11:59:37 +0000 (12:59 +0100)
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.

README.md
core/30_env/30_env.ax-io
core/30_env/30_env.zshrc [deleted file]
plugins/calendar/calendar.ax-io
plugins/icalbuddy/icalbuddy.ax-io

index 3ddbd0cb9287f4bae4d42f278a3b7e5943c8a11c..8e059fce2f0f304d6379b8376bde0c67a3e0e7ad 100644 (file)
--- 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`
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"
diff --git a/core/30_env/30_env.zshrc b/core/30_env/30_env.zshrc
deleted file mode 100644 (file)
index b8ee833..0000000
+++ /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 <https://bugzilla.redhat.com/show_bug.cgi?id=129682#c1>).
-# 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
index 101320000d77120ee6a4748e9ba5aad1e9999ee9..53040a624592408929950b065dce06b91a8cc580 100644 (file)
@@ -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
index 7c6c6c36b4925a3420f093b59ead90482ac3271b..c91ed76f08a54c7974dbf8b7d063769d921decb1 100644 (file)
@@ -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="»"