Skip to content

Commit c428d4e

Browse files
committed
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
1 parent e77e938 commit c428d4e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

z.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,19 @@
2929
}
3030

3131
_z() {
32+
DEFAULT_CACHE_DIR="$HOME/.cache/z"
33+
34+
# Backwards compatible _Z_DATA definition
35+
if [[ -n $_Z_DATA ]]; then
36+
datafile=$_Z_DATA
37+
# respect user specific XDG settings
38+
elif [[ -n $XDG_CACHE_HOME ]]; then
39+
datafile=$XDG_CACHE_HOME/z/z
40+
# fallback to default XDG directory
41+
else
42+
datafile=$DEFAULT_CACHE_DIR/z
43+
fi
3244

33-
local datafile="${_Z_DATA:-$HOME/.z}"
3445

3546
# if symlink, dereference
3647
[ -h "$datafile" ] && datafile=$(readlink "$datafile")

0 commit comments

Comments
 (0)