Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support XDG-specification #277

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/state/$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