agkozak / zsh-z

Jump quickly to directories that you have visited "frecently." A native Zsh port of z.sh with added features.
MIT License
2.02k stars 76 forks source link

When setting `ZSHZ_DATA` to an XDG basedir location, the directory doesn't get created #72

Closed mattmc3 closed 1 year ago

mattmc3 commented 1 year ago

One of the annoyances I've always had with rupa/z is that if you set _Z_DATA to an XDG compliant location (https://github.com/agkozak/zsh-z/issues/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... https://github.com/agkozak/zsh-z/blob/82f5088641862d0e83561bb251fb60808791c76a/zsh-z.plugin.zsh#L164

...to this?

[[ -f $datafile ]] || { mkdir -p "${datafile:h}" && touch "$datafile" }
agkozak commented 1 year ago

Here's my thinking:

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.

mattmc3 commented 1 year ago

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.