Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/fix-72' into fix-72
Browse files Browse the repository at this point in the history
  • Loading branch information
agkozak committed Jan 27, 2023
2 parents f245417 + 91c4ca6 commit c28d8f5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions zsh-z.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,19 @@ zshz() {
local REPLY
local -a lines

# Allow the user to specify the datafile name in $ZSHZ_DATA (default: ~/.z)
# Allow the user to specify a custom datafile in $ZSHZ_DATA (or legacy $_Z_DATA)
local custom_datafile="${ZSHZ_DATA:-$_Z_DATA}"

# If a datafile was provided as a standalone file without a directory path
# print a warning and exit
if [[ -n ${custom_datafile} && ${custom_datafile} != */* ]]; then
print "ERROR: You configured a custom Zsh-z datafile (${custom_datafile}), but have not specified its directory." >&2
exit
fi

# If the user specified a datafile, use that or default to ~/.z
# If the datafile is a symlink, it gets dereferenced
local datafile=${${ZSHZ_DATA:-${_Z_DATA:-${HOME}/.z}}:A}
local datafile=${${custom_datafile:-$HOME/.z}:A}

# If the datafile is a directory, print a warning and exit
if [[ -d $datafile ]]; then
Expand All @@ -161,7 +171,7 @@ zshz() {

# Make sure that the datafile exists before attempting to read it or lock it
# for writing
[[ -f $datafile ]] || touch "$datafile"
[[ -f $datafile ]] || { mkdir -p "${datafile:h}" && touch "$datafile" }

# Bail if we don't own the datafile and $ZSHZ_OWNER is not set
[[ -z ${ZSHZ_OWNER:-${_Z_OWNER}} && -f $datafile && ! -O $datafile ]] &&
Expand Down

0 comments on commit c28d8f5

Please sign in to comment.