Skip to content

Commit

Permalink
Support XDG-specification
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mstruebing committed Nov 29, 2019
1 parent e77e938 commit dbdf5c5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion z.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,20 @@
}

_z() {
local DATA_FILE_NAME="z"
local DIRECTORY_NAME="z"

local datafile="${_Z_DATA:-$HOME/.z}"
# fallback to default XDG directory
local DEFAULT_DATA_DIR="$HOME/.local/share/$DIRECTORY_NAME"
local datafile=$DEFAULT_DATA_DIR/$DATA_FILE_NAME

# Backwards compatible _Z_DATA definition
if [[ -n $_Z_DATA ]]; then
datafile=$_Z_DATA
# respect user specific XDG settings
elif [[ -n $XDG_DATA_HOME ]]; then
datafile=$XDG_DATA_HOME/$DIRECTORY_NAME/$DATA_FILE_NAME
fi

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

0 comments on commit dbdf5c5

Please sign in to comment.