zsh-z icon indicating copy to clipboard operation
zsh-z copied to clipboard

Fall-back directories / glob patterns

Open zachriggle opened this issue 3 years ago • 7 comments

I work with hundreds of different Git repositories, but often won't do anything in a particular repository for several months at a time. By the time I need to z somerepo, it no longer exists in the ~/.z cache of recent directories.

I've tried to remedy this with a script that cd's into all subdirectories with a .git directory, and does zshz --add $dir for each one that does.

However, even with this, it seems that entries get aged off before I eventually need them.

From zshz -l | wc -l I see that there are exactly 200 directories that are remembered. I'm not sure if this is coincidence or a hard limit (I liked at the source, and couldn't tell).

It would be nice to have either of:

  • Option for disabling the "age-off" functionality entirely
  • Disable age-off, but for subpaths of some array of paths
  • Disable age-off, but only for paths which contain a .git directory
  • Keep age-off the same, but in the event there are NO matches for a e.g. zshz foo, use a user-defined array of glob expressions and go with the best match

zachriggle avatar Sep 03 '21 21:09 zachriggle

ZSHZ_MAX_SCORE is supposed to address this issue, but I can see how it might be insufficient in some cases. You and I clearly use the command line a lot! I'll work on this. Thanks, as always, for your thoughtful analysis.

agkozak avatar Sep 03 '21 23:09 agkozak

@zachriggle I've just committed to the no-age branch a patch that makes it so that if you set ZSHZ_MAX_SCORE=0, it disables aging entirely. Give that a try and see if it helps.

agkozak avatar Sep 16 '21 17:09 agkozak

Just updated / pulled / merged with my local changes, I'll give this a go for a while and see how it goes!

zachriggle avatar Nov 08 '21 20:11 zachriggle

Looks like it works! For some reason I had to do two passes of z --add $PWD for each of the directories I want, but it's now stable.

$ z -l | wc -l
     624

zachriggle avatar Nov 08 '21 23:11 zachriggle

For some reason I had to do two passes of z --add $PWD for each of the directories I want

See if you can figure out reproducible steps to demonstrate that problem. I want to identify it and fix it.

By the way, I've updated your no-age branch with the new addition to the develop branch (the ability to --add relative paths), so you can keep using no-age and make sure it works the way you want it to.

agkozak avatar Nov 10 '21 00:11 agkozak

Everything's been working great!! Thanks for adding the ZSHZ_MAX_SCORE / no-age branch.

I see no reason not to merge it to the main branch.

zachriggle avatar Nov 11 '21 13:11 zachriggle

I hesitate to release this feature as-is. The datafile, which gets processed almost every time the prompt is drawn, could grow to be very large. On an older, slower computer, the effect is really terrible -- I played around with indexing part of the FreeBSD source on an old Windows computer. A nightmare.

Could you do me a favor sometime? Now that your ~/.z datafile is really large, see how many entries it has:

z -l | wc -l

Back it up before your do the following experiment. Then change ZSHZ_MAX_SCORE to a really large number, say

ZSHZ_MAX_SCORE=999999999999999999

Restart the shell and run

z -l | wc -l

If the number doesn't change, you'll know that that setting is large enough to stop your current database is aging. Then lower ZSHZ_MAX_SCORE gradually. If you find that you can knock a lot of 9s off that number without the database getting pruned, we'll know that you can afford to use a large but still finite setting.

agkozak avatar Nov 17 '21 19:11 agkozak