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 c428d4e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion z.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@
}

_z() {
DEFAULT_CACHE_DIR="$HOME/.cache/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
# fallback to default XDG directory
else
datafile=$DEFAULT_CACHE_DIR/z
fi

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

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

0 comments on commit c428d4e

Please sign in to comment.