Skip to content

Commit dbdf5c5

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 dbdf5c5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

z.sh

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

3131
_z() {
32+
local DATA_FILE_NAME="z"
33+
local DIRECTORY_NAME="z"
3234

33-
local datafile="${_Z_DATA:-$HOME/.z}"
35+
# fallback to default XDG directory
36+
local DEFAULT_DATA_DIR="$HOME/.local/share/$DIRECTORY_NAME"
37+
local datafile=$DEFAULT_DATA_DIR/$DATA_FILE_NAME
38+
39+
# Backwards compatible _Z_DATA definition
40+
if [[ -n $_Z_DATA ]]; then
41+
datafile=$_Z_DATA
42+
# respect user specific XDG settings
43+
elif [[ -n $XDG_DATA_HOME ]]; then
44+
datafile=$XDG_DATA_HOME/$DIRECTORY_NAME/$DATA_FILE_NAME
45+
fi
3446

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

0 commit comments

Comments
 (0)