Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question

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.

share|improve this answer

You could of course tinker with this so that it worked for any given folder or set of files, but first you should understand the reason it doesn't do that now.

On linux, file extensions don't matter, the only thing that matters is the execute bit. Things can be executed whether they are really binary or just text in the form of a script. Your criteria of "not binaries" does not match up well with the distinctions made by Linux about what a file is or isn't.

That being said it wouldn't be too hard to write a custom completion function to replace the file name glob completion for a given command that would list all files but exclude the ones that have '.c' versions. It would require some overhead that would slow the tab completion down a little.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.