ZSH tab completion: only complete files and not binaries

autocompletevimzsh

Is it possible to make a custom zsh completion file,so when hitting tab for filenames it avoids completing the binaries?
For example,I have 2 files , myprogram.c and myprogram,the binary,is it possible so when I do vim myprog(tab) it automagically completes it to myprogram.c,not myprogram?
Thanks in advance!

Best Answer

You can ignore some patterns in completions by tuning completion styles with the zstyle built-in. There are examples in the zsh guide.

For example, to ignore *.o files when completing files to edit with vim, you can put this in your .zshrc:

zstyle ':completion:*:*:vim:*:*files' ignored-patterns '*.o'

This won't work to exclude executables in a useful way. You can exclude *~*.*, or more precisely (|*/)[^/.]##, but this excludes every file name that doesn't contain a ., including scripts and even worse directories. As far as I know, the completion ignore mechanism can't check for the existence or type of files, it just matches text patterns.

Related Question