+### temp
+# NOTE: it's intentional to separate POSIX tmp for each session (spec says
+# programs should not expect data there to be long-lived) and to keep the
+# same runtime dir and not create a new one if a new login shell is
+# spawned, since the XDG spec calls for the same dir to be utilized for
+# each "session".
+if [[ ! -v _sev_setup_tmp ]] {
+ t=${TMPDIR:-${TEMP:-${TMP:-/tmp}}}/.home-$LOGNAME
+ h=~/tmp
+ [[ ! -e $t ]] && mkdir -pm700 $t 2>/dev/null
+ if [[ ! -d $t ]] {
+ [[ -o interactive ]] &&
+ print -P "%F{red}!!! Can't create temp dir $t%f"
+ # fallback bare directories
+ [[ -h $h ]] && unlink $h 2>/dev/null
+ [[ ! -e $h ]] && mkdir -m700 $h 2>/dev/null
+ }
+ # [re-]create link to our tmp
+ [[ -h $h || ! -e $h ]] && ln -sfn $t $h 2>/dev/null
+ # finally create our subdir for this session
+ export _sev_tmp=$h/.session.$$
+ # ensure dir doesn't exist. if there is already something there it is
+ # likely a stale directory or something is very broken—assume the former.
+ # the user could also want dirs recreated by unsetting the var.
+ if [[ -h $_sev_tmp ]] {
+ unlink $_sev_tmp 2>/dev/null
+ } elif [[ -e $_sev_tmp ]] {
+ rm -rf $_sev_tmp 2>/dev/null
+ }
+ mkdir -m700 $_sev_tmp 2>/dev/null
+ export TMPDIR=$_sev_tmp TEMP=$_sev_tmp TMP=$_sev_tmp
+ unset t h
+ export _sev_setup_tmp=
+}
+
+### xdg