When setting `ZSHZ_DATA` to an XDG basedir location, the directory doesn't get created
mattmc3 opened this issue · 2 comments
One of the annoyances I've always had with rupa/z is that if you set _Z_DATA
to an XDG compliant location (#20), you have to make sure the directory exists with something like this:
_Z_DATA=${XDG_DATA_HOME:=$HOME/.local/share}/z/data
if [[ ! -f $_Z_DATA ]]; then
mkdir -p ${_Z_DATA:h}
touch $_Z_DATA
fi
I tried zsh-z and it suffers from the same issue:
ZSHZ_DATA=${XDG_DATA_HOME:=$HOME/.local/share}/zsh-z/data
# error: zshz:28: no such file or directory: ~/.local/share/zsh-z/data
If a user sets the path they want to use for the z database, zsh-z should create it for them. Would you accept a PR that changes this line...
Line 164 in 82f5088
...to this?
[[ -f $datafile ]] || { mkdir -p "${datafile:h}" && touch "$datafile" }
Here's my thinking:
- Any valid value for
ZSHZ_DATA
or_Z_DATA
should include an explicit directory location. - Let's not make any assumptions about what the user meant, but rather issue an error message when appropriate.
Instead of what you have in your second commit, we could do something like the following: right before we assign datafile
, we could have
# If the user has configured a custom datafile, make sure its directory is
# specified
if [[ -n ${ZSHZ_DATA:-${_Z_DATA}} && ${ZSHZ_DATA:-${_Z_DATA}} != */* ]]; then
print "Zsh-z: You have configured a custom datafile (${ZSHZ_DATA:-${_Z_DATA}}), but you have not specified its directory."
return
fi
Let me know what you think. And thanks for your patience.
I like it. I just pushed a new commit. I tweaked it just a tiny bit, so let me know if you were expecting something closer to your original ask or if this is acceptable.