Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.