zimfw / completion

Enables and configures smart and extensive tab completion.
MIT License
37 stars 10 forks source link

Case sensitive(ish) tab complete #2

Closed Redoubts closed 1 year ago

Redoubts commented 5 years ago

I noticed that if I have a directory like (Directory, file.txt, FilteredFile.txt), and I hit F<tab>, I get a choice between file.txt and FilteredFile.txt. Given I started capitalized, I expected a direct complete rather than a choice. Turns out, a small addition can fix this.

Here, F<tab> will give me the capital file,f<tab> will give me the lowercase file, and even d<tab> will give me Directory, so I don't have to be all that careful with this option on.

ericbn commented 5 years ago

@Redoubts, your change replaces the case insensitive by a smart case sensitive match.

There's another (simpler) way to accomplish this:

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' '+r:|?=**'

I have second thoughts about smart case sensitivity here, because Zsh does not support smart case for globs for example. We use case insensitive there:

# Make globbing (filename generation) not sensitive to case.
setopt NO_CASE_GLOB

Also, the matcher-list already drove me insane with the unfinished discussion at https://github.com/zimfw/zimfw/issues/212

~You gave me an insight on a config the might have what you want (smart case) and also fix the issues in that discussion (thanks to smart case):~

zstyle ':completion:*' matcher-list 'r:|?=**' 'm:{a-zA-Z}={A-Za-z}' '+r:|?=**'

EDIT: Last idea was a bad idea, did strike it out.

ericbn commented 5 years ago

@protist ☝️

protist commented 5 years ago

@ericbn Thanks for the mention. I'd actually forgotten the details of the issue, so I read most of it again. This seems to work well mostly, but it appears to conflict with your comment here, where you suggested completion should prioritise the beginning of the word. I think I agree with this.

$ rm *
$ touch foobar qwefoo
$ touch foo<TAB>

This offers to complete both files, whereas both of us would want it to complete only foobar. (There's a mention later on in the issue where an additional solution was also discounted because of this behaviour.)

ericbn commented 5 years ago

Right @protist, I also had to read most of the comments in the issue to refresh my memory. And yes, it's annoying to have a fuzzy matcher first. That was my idea again here. My bad.

@Redoubts's suggestion is to add a case sensitive matcher first.

I have seconds thoughts about this.

protist commented 5 years ago

Thanks @ericbn . TBH I don't have strong feeling regarding the case sensitivity, which was why I didn't mention it earlier. I can see arguments for both options.

rockindy commented 3 years ago

The current case insensitive config works well in Mac, but the case sensitive works better in Linux. @ericbn Could we have an option to switch those behaviors easily?

ericbn commented 3 years ago

@rockindy, yeah I think it's more than fair that we have an option to configure the case sensitivity.

ericbn commented 1 year ago

zstyles that allow configuring the case sensitivity were added in #11. Closing this.