zoxide
zoxide copied to clipboard
Smart case search
Hello,
vim has very handy option smartcase
to do case-sensitive search if there is any capital letter in search query, otherwise search is case-insensitive. I have directory called V
, and if I type z V
I am moved, e.g. into ~/.config/nvim
directory. I have to use longer z parent/V
to give z
a hint. Therefore, I think it makes sense for z
to support notion of smart case as well, it would make tool more comfortable to use.
One question here is -- should z doc Foo
match ~/Documents/Foo
? I'd think not -- either the whole query should be smartcase or none of it should be.
I also think normalizing diacritics (café -> cafe
) would be great. Possible queries should be:
Accent normalization:
-
z cafe
matches~/Pictures/Café
-
z café
does not match~/Pictures/Cafe
Case normalization:
-
z cafe
matches~/Pictures/Cafe
-
z Cafe
does not match~/Pictures/cafe
One question here is -- should
z doc Foo
match~/Documents/Foo
? I'd think not -- either the whole query should be smartcase or none of it should be.
I agree, it should be all or nothing. Or perhaps there should be two types of switches, one that applies case-sensitive search globally if there is at least one with capital letter in search query, and other that infers smart case for each word of query individually.
I also think accent normalization (
café -> cafe
) would be great. Possible queries should be:Accent normalization:
* `z cafe` matches `~/Pictures/Café` * `z café` does not match `~/Pictures/Cafe`
Case normalization:
* `z cafe` matches `~/Pictures/Cafe` * `z Cafe` does not match `~/Pictures/cafe`
That would be great as well to have, I happen to speak in language with diacritics, but if I were to choose one of the two only, then it would be smart case. ;)
Somewhat related: #114
As for me, I would like zoxide to match case-insensitively all the time, with an option to enable case-sensitive matching. Smart case seems overkill.
@kidonng I'm curious as to why you'd want to disable smartcase matching. I wouldn't expect anyone to use uppercase in a query unless they were hoping for results with the same uppercase letters in them.
I'm willing to work on this, if that's ok! I'll be trying to send in a PR by tomorrow.
@PurpleMyst there's already a pending PR on improving search which will very likely conflict with this. I haven't really had time to look into it yet, but for now, I'd recommend against creating a separate PR.
@kidonng I'm curious as to why you'd want to disable smartcase matching. I wouldn't expect anyone to use uppercase in a query unless they were hoping for results with the same uppercase letters in them.
I seldom disable smart case in any program, but I sometimes want true case-insensitive when I search for copied text that contains capitals. For example if I want to search for "armv7_unknown" but copied text from: CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-musleabihf-gcc.
And case sensitivity (no smart case) is useful when there's a great pollution of upper case strings but you want to find a lower case string.
I suggest the option to disable smart case can be deferred until someone insistently asks for it, since (though it's important) it's so uncommonly used. It may never be an issue in zoxide since zoxide's use case is partly to avoid copying long strings. And because zoxide works on paths rather than codebases, there will be less collision between different cases. Paths don't have the same case convention issues as code (different kinds of tokens having different capitalization).
BTW, I just implemented smart case matching in my branch. If you want to try my version with smart case and new keyword-based scoring (I think these features will make it into the official version at some point), you can install it with: cargo install zoxide --git https://github.com/lefth/zoxide
Somewhat related to that, a lot of characters with diacritics have several representations, for example é
can be U+0065 U+0301
or simply U+00E9
. It would be nice if zoxide could merge those, perhaps by running everything (both queries and file/dir lists) through some normalization transformation. Right now, at least on macOS, if my folder is named café
(U+0065 U+0301
, the preferred encoding when renaming things in Finder) and I z café
(U+00E9
, what actually gets typed in my shell), I get no match.