diff --git a/z.sh b/z.sh old mode 100644 new mode 100755 index 2b7f87a..e89a487 --- a/z.sh +++ b/z.sh @@ -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")