How can zsh be configured to autocomplete directory name with camelcase matching?

This works for me:

zstyle ':completion:*' matcher-list 'r:[^A-Z0-9]||[A-Z0-9]=** r:|=*' 

Then I can do this in a test directory:

touch MyReallyLongName MyReallyLongAndFunName MyReallyLongAndNotReallyFunName
ls MRLANRFN<TAB>
ls MyReallyLongAndNotReallyFunName

I cobbled it together from tips in the Zshell User's Guide.


I got this to work "quite well" by adding a file _camel_case to my personal ~/.zsh/functions folder (take any folder that is in your $fpath variable) with the following content:

#autoload

[[ -z "$PREFIX" ]] && return 1

relpath=$(dirname $PREFIX)

[[ -e $relpath ]] || return 1

files=$(ls $relpath)

regex=$(echo $(basename $PREFIX) | sed -e 's/\([A-Z][^A-Z]*\)/\1[^A-Z]+/g')

correctedfiles=($(echo $files | grep -P $regex | sed -e :a -e '$!N;s/\n/ /;ta'))

results=($(for file in $correctedfiles; do echo "$relpath/$file"; done))

compadd -U -f -- $results

Then, I added the following line to my ~/.zshrc

zstyle ':completion:*' completer _complete _correct _path_files _camel_case

Note that this is most probably not a "good" solution as I do not have too much knowledge of the completion system of zsh (only few people really have, I guess), but it does exactly what you described in your question.