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

Fix #72: mkdir for datafile if necessary #73

Closed mattmc3 closed 1 year ago

mattmc3 commented 1 year ago

See #72

mattmc3 commented 1 year ago

Also, I verified that if ZSHZ_DATA is set to a file name with no directory path, the :h suffix will helpfully return '.'. This will ensure that mkdir -p succeeds on that edge case.

ZSHZ_DATA=my_z_database

# the h param expansion returns '.' in this case
echo ${ZSHZ_DATA:h}

# mkdir -p won't fail on this edge case
mkdir -p ${ZSHZ_DATA:h}
agkozak commented 1 year ago

Thank you for the very clever solution.

I wonder if we should do anything further about the edge case. If I accidentally put in my .zshrc

ZSHZ_DATA=quux

instead of

ZSHZ_DATA=~/quux

Zsh-z will happily create a quux file in every directory I navigate to. That is literally what I told it to do, but it's presumably never what I want.

I should be able to address this issue early next week.

mattmc3 commented 1 year ago

Zsh-z will happily create a quux file in every directory I navigate to. That is literally what I told it to do, but it's presumably never what I want.

That's a great callout. I pushed another one-liner commit that addresses this:

[[ "${datafile:h}" !=  '.' ]] || datafile="${ZDOTDIR:-$HOME}/$datafile"

Let me know if how I handled it works for you. It might seem a bit clever, but I think it reads pretty clear that either the basedir isn't '.' (everywhere), or set the dir to where zsh considers home.

agkozak commented 1 year ago

Your addition was great. I just merged it to master. Thanks again!