- export XDG_CACHE_HOME=~/tmp
- # NOTE: it's intentional to keep the same runtime dir for the whole session
- # and not create a new one if a new login shell is spawned, since the
- # spec calls for the same dir to be utilized for each "session".
- export XDG_RUNTIME_DIR=~/tmp/xdg.$$
-}
-
-## temp
-if [[ ! -v _sev_setup_tmp ]] {
- t=${TMPDIR:-${TEMP:-${TMP:-/tmp}}}/.home-$LOGNAME
- if [[ ! -e $t ]] {
- mkdir -m700 $t 2>/dev/null
- if [[ ! -d $t ]] {
- [[ -o interactive ]] &&
- print -P "%F{red}!!! Can't create temp folder $t%f"
- # fallback bare directories
- [[ -h $XDG_CACHE_HOME ]] && unlink $XDG_CACHE_HOME 2>/dev/null
- [[ ! -e $XDG_CACHE_HOME ]] && mkdir -m700 $XDG_CACHE_HOME 2>/dev/null
- }
- }
- if [[ -e $t ]] {
- export TMPDIR=$t TEMP=$t TMP=$t
- # [re-]create link to our tmp if safe
- [[ -h $XDG_CACHE_HOME || ! -e $XDG_CACHE_HOME ]] &&
- ln -sf $t $XDG_CACHE_HOME 2>/dev/null
- } else {
- # ensure proper tmp vars, e.g. msys2 does not set TMPDIR
- : ${TMPDIR:=${TEMP:-${TMP:-/tmp}}}
- : ${TEMP:=$TMPDIR}
- : ${TMP:=$TMPDIR}
- }
- unset t
- export _sev_setup_tmp=
-}
-
-## xdg
-if [[ ! -v _sev_setup_xdg ]] {
- # create xdg runtime dir
- # NOTE: spec says the dir should only exist for the lifetime of the
- # session, so if there is already something there it is likely stale
- # or something is very broken—assume the former.
- [[ -e $XDG_RUNTIME_DIR ]] && rm -rf $XDG_RUNTIME_DIR 2>/dev/null &&
- mkdir -m700 $XDG_RUNTIME_DIR 2>/dev/null
+ export XDG_CACHE_HOME=$_sev_tmp/.xdg.cache
+ export XDG_RUNTIME_DIR=$_sev_tmp/.xdg.runtime
+ # create xdg tmp dirs
+ for x in $XDG_CACHE_HOME $XDG_RUNTIME_DIR; do
+ # same as in temp creation, ensure it doesn't exist
+ if [[ -h $x ]]; then
+ unlink $x 2>/dev/null
+ elif [[ -e $x ]]; then
+ rm -rf $x 2>/dev/null
+ fi
+ mkdir -m700 $x 2>/dev/null
+ done