rupa / z

z - jump around
Do What The F*ck You Want To Public License
16.4k stars 1.17k forks source link

make matching behavior slightly more intuitive #157

Open anachrome opened 9 years ago

anachrome commented 9 years ago

normal z matching behavior, especially with respect to the common() function, is a little odd:

mkdir -p aaa/bbb
cd aaa
cd -
cd aaa/bbb
cd -
z aaa # goes to aaa, even though aaa/bbb has higher frecency
cd -
mkdir -p zzz/aaa
cd zzz/aaa
cd -
cd aaa/bbb
cd -
cd aaa/bbb # increasing the frecency of the subdir
cd -
z aaa # goes to ./aaa/bbb (deeper in the directory tree than I am trying to jump)

In fact, if an unrelated path matching /aaa/ is in z's database, and aaa/bbb is of higher frecency than aaa, there is no way to jump to aaa without also jumping deeper into aaa/bbb.

This patch changes the matching behavior so z will only jump to a deeper directory if it is explicitly matched - e.g., z aaa will never jump below the directory matching aaa, which I find to be slightly more intuitive.

GammaGames commented 5 years ago

I was wondering if anyone had a fix for this behavior, using z modules to try and go to a modules folder almost always takes me to modules/app1 or modules/app2, depending on which one I was in recently. I saw @rupa merged another request recently, I wonder if he has any thoughts on this one?

rupa commented 5 years ago

yeah, i should really think about merging this. at the very least, it gets rid of the code i hate most. definitely some "i have this problem and this fixes it and doesn't make anything else worse" comments help :)

GammaGames commented 5 years ago

I’ll put it on my computer and test it for a week or two, I use z a handful of times a day so I think it would be a decent indicator of real world use. Thank you!

Edit: There have been significant changes since this was submitted, I'll try to get all the changes into a branch that works first. Then I'll test it out