zsh-z
zsh-z copied to clipboard
Feature: Prefer exact matches
As always, thank you @agkozak for making the pure-Zsh port of Z.
One of the things I tend to butt up against that is that the "frecency" prefers top matches over exact matches.
This might be something to hide behind a non-default environment variable setting, but currently I have:
$ env | grep ZSHZ
ZSHZ_CASE=smart
ZSHZ_NO_RESOLVE_SYMLINKS=1
$ zshz -l git | tail -3
746426 /Users/zachriggle/github.com/git
1327925 /Users/zachriggle/github.com/zsh
2103788 /Users/zachriggle/github.com/shellcheck
$ zshz -e git
/Users/zachriggle/github.com/shellcheck
And if I do z git
it will go to the shellcheck
directory. Since git
has an EXACT match, I'd kind of prefer that it went there instead. I dug into the code for zsh-z
but, despite thinking I know how to Zsh pretty well, can't figure out how or where to add this.
I was hoping that ZSHZ_UNCOMMON
would fix this, but it has different (but understandable) behavior.
$ ZSHZ_UNCOMMON=1 zshz -e git
/Users/zachriggle/github.com
It would be nice if there was an e.g. ZSHZ_PREFER_EXACT_MATCHES
setting that would... prefer exact matches.
Thanks so much for the kind words!
I'll put some thought into this.
I think this option would be great to have but for now, you can always force an exact match by using slashes. So in this case, "z /git/" would give the correct result. In a way, this is just obvious behavior of the matching algorithm, but I thought I'd mention it here for others since it took me about a month before I noticed this