From c428d4ee4d05b41f42e20c4d884831b813dff004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Fri, 29 Nov 2019 09:31:53 +0100 Subject: [PATCH] Support XDG-specification see: https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.6.html This is backwards compatible with the old `_Z_DATA` env-var but enhances the user experiences with the XDG-specification. closes #267 --- z.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/z.sh b/z.sh index 2b7f87a..e53e866 100644 --- a/z.sh +++ b/z.sh @@ -29,8 +29,19 @@ } _z() { + DEFAULT_CACHE_DIR="$HOME/.cache/z" + + # Backwards compatible _Z_DATA definition + if [[ -n $_Z_DATA ]]; then + datafile=$_Z_DATA + # respect user specific XDG settings + elif [[ -n $XDG_CACHE_HOME ]]; then + datafile=$XDG_CACHE_HOME/z/z + # fallback to default XDG directory + else + datafile=$DEFAULT_CACHE_DIR/z + fi - local datafile="${_Z_DATA:-$HOME/.z}" # if symlink, dereference [ -h "$datafile" ] && datafile=$(readlink "$datafile")