z
z copied to clipboard
Option to prefer shorter matches
When there are multiple matches (e.g. dir X
and the subdir X/Y
), z X
sometimes jumps to X/Y
. Sometimes, it would be preferable to have z
jump to the shortest match (X
in this example).
There's some code in z
that does select the shortest match, but only if all matches share the same prefix. So if you you have:
/home/foo/bar
/home/foo/bar/baz
we'll select the first, even if the second is weighted higher. But if you have:
/bar/baz
/home/foo/bar
/home/foo/bar/baz
we just select the highest weight.
I've put a good amount of thought into improvements but I haven't really come up with anything I like better. I'd like to avoid adding flags if possible - keep it simple. In practice, since the arguments to z
are regular expressions, I've been able to pretty quickly find a mnemonic (might be a couple arguments) for 'hard to get to' directories like this (for example one machine I share with several coworkers z bin
always wants to go to /bin
and I always want to go to ~/bin/
), once that's in my muscle memory I barely notice it.
I also have a branch that I've been using/testing for a while where order of arguments matter, and I'm this close to merging that to master. It never bothers me, and in situations like this, sometimes helps a lot.
I'll keep this open because I'm not done thinking about this, and am interested in any comments.
Would it be an option to add a command-line option that makes z
(1) display a (numbered) list of matching directories if there are more than one, (2) let the users type a number (or set to 0 if there is only one match), (3) jump to that directory? I guess this could resolve all sorts of unintended behaviour.
For the following dirs:
/foo/foobar
/foo
Is it possible that I type z foo
and take me into /foo/bar
if I am in the /foo/
dir?
Or, how about type z foo foo
and take me in /foo/bar
?
The first option is what autojump
does, I prefer the second one.