Chris N
Chris N

Reputation: 949

Have zsh autocompletion use case-sensitive matches only if I typed uppercase

How can I make zsh auto-completion give me case-insensitive matches if I typed lowercase, but case-sensitive ones if I typed uppercase? For example, if I type "HOtab" it should offer HOME and HOST, but if I type "hotab" it should offer HOME, HOST, host, hostinfo, and hostname.

The case-insensitive part is easy (matcher-list m:{a-zA-Z}={A-Za-z}), and I found Have zsh return case-insensitive auto-complete matches, but prefer exact matches, but that's not quite what I want — if there are any exact lowercase matches, it will not offer the uppercase ones. I suspect the answer has to do with a left-anchored matcher, but I can't get it to work.

Upvotes: 2

Views: 1144

Answers (1)

Chris N
Chris N

Reputation: 949

What I originally had in mind was that if the typed string contained any uppercase characters, it should be matched exactly. I still don't know how to do that. However, a slightly relaxed form works well enough for my purposes:

  1. Lowercase characters should match upper- and lowercase characters.
  2. Uppercase characters should only match themselves.

Framed like that, the answer is obvious: Remove my existing fully case-insensitive matcher-list style (m:{a-zA-Z}={A-Za-z}) and replace it with this:

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

Upvotes: 2

Related Questions