Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Case-insensitive completion



On Sep 15,  9:08pm, Jesper Holmberg wrote:
} Subject: Re: Case-insensitive completion
}
} aac.txt aAa.txt Aaa.txt aAb.txt
} 
} If I want to complete for "Aaa.txt", it works well, I just put capital "A"
} and hit tab, and since the matching is only one-way, the completer knows
} that I really want a capital A, and gives me Aaa.txt.
} 
} If, on the other hand, I wanted aac.txt, hitting "aa" would not really
} help me, since "aAa.txt", "Aaa.txt" and "aAb.txt" would all be proposed
} before my aac.txt. I am thus looking for an easy way to specify that 
} *this time* I really want to match on literally "aa".
} 
} Perhaps what I want is unachievable, but has anyone solved this in a smart
} way?

Normally the way to do that would be to use different keybindings for
"complete case-insensitively" vs. "complete case-sensitively" and tell
zsh your preference by which of them you invoke.

Start with zstyles something like this:

  zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
  zstyle ':completion:*:case-sensitive:*' matcher-list ''
  zstyle ':completion:*' completer _expand _complete _ignored

Then, in a file (name doesn't matter much) somewhere in the path where
compinit looks for completion functions, you put:

---- 8< ---- snip ---- 8< ----
#compdef -k complete-word \C-xI
_main_complete _expand _complete:case-sensitive _ignored
---- 8< ---- snip ---- 8< ----

Replace \C-xI (control x shift i) with whatever keybinding you want to
have attached to case-sensitive completion.

You could get a little fancier with the function and avoid hardwiring
the list of completers by copying some of the code from _main_complete
to get the matcher-list context, then modify that list of matchers to
attach :case-sensitive where needed, before calling _main_complete.

Warning, I didn't actually test any of the above.



Messages sorted by: Reverse Date, Date, Thread, Author