bjd2385 bjd2385 - 1 month ago 7x
Linux Question

Bash - expected file extension on tab

I'm not sure if this is something that can be done in the Linux/Unix terminal, so I thought I'd ask.

For certain programs (unfortunately I can't think of any besides

off the top of my head, which on tab auto-'extends' the .aux extension) when I'm finished typing out the file name (minus dot and extension) in front of it, I've noticed that if I hit
it will 'auto-complete' the dot + file extension.

Is this something you can actually control somehow ? For example, if I wrote a bash script (we'll call it
) that only worked with *.tex files, I could do the following:

$ ./ nameOfProgram -- tab and autocomplete .tex extension --

Certainly it's not inherent to the bash script itself, but by some other means that recognizes I'm using said executable.

Sometimes, as is often the case while using LaTeX, there are multiple files with the same base name but different extensions in the same directory - I would like it to only accept that which has the predefined extension.


It is certainly possible to define a custom completion function for which only matches *.tex files. Writing a good completion function is a broad task, but you can do something very simple with

# Add to your .bashrc file to enable in every shell, not just
# the current shell
complete -G '*.tex'

which will only treat files matching *.tex as valid completions for any argument to