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 rupa#267
  • Loading branch information
mstruebing committed Nov 29, 2019
1 parent e77e938 commit b3f1a4e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion z.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@
}

_z() {
DEFAULT_CACHE_DIR="$HOME/.cache/z"

local datafile="${_Z_DATA:-$HOME/.z}"
# fallback to default XDG directory
local datafile=$DEFAULT_CACHE_DIR/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
fi

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

0 comments on commit b3f1a4e

Please sign in to comment.