Skip to content

Commit b3f1a4e

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 b3f1a4e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

z.sh

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

3131
_z() {
32+
DEFAULT_CACHE_DIR="$HOME/.cache/z"
3233

33-
local datafile="${_Z_DATA:-$HOME/.z}"
34+
# fallback to default XDG directory
35+
local datafile=$DEFAULT_CACHE_DIR/z
36+
37+
# Backwards compatible _Z_DATA definition
38+
if [[ -n $_Z_DATA ]]; then
39+
datafile=$_Z_DATA
40+
# respect user specific XDG settings
41+
elif [[ -n $XDG_CACHE_HOME ]]; then
42+
datafile=$XDG_CACHE_HOME/z/z
43+
fi
3444

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

0 commit comments

Comments
 (0)