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

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

Closed
mattmc3 opened this issue Dec 28, 2022 · 2 comments
Assignees

Comments

@mattmc3
Copy link
Contributor

mattmc3 commented Dec 28, 2022

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...

[[ -f $datafile ]] || touch "$datafile"

...to this?

[[ -f $datafile ]] || { mkdir -p "${datafile:h}" && touch "$datafile" }
@agkozak
Copy link
Owner

agkozak commented Jan 17, 2023

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.

@mattmc3
Copy link
Contributor Author

mattmc3 commented Jan 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants