The people who package programs often seem to have an overly broad opinion as to the types of files their program will be used to open, as shown in the bash autocompletion setup that they create. For example, it often happens that I have files a.svg and a.jpg, where a.jpg is the rendering of a.svg into a bitmap. I use inkscape for editing svg files, and gimp for editing jpg files. But if I type "inkscape a" or "gimp a" and hit the tab for autocomplete, each of these programs, like an overenthusiastic puppy, imagines that I might want to edit either a.svg or a.jpg, and I have to disambiguate.

An even sillier example (which looks more like a bug) is that gimp offers to open a.odt (a libre office file), but gives an error if I actually try to do that.

How does one go about paring down the autocompletion settings of programs like these in order to get a customized setup that minimizes inconveniences?

1 Answer 1


First, let me clear up a few misconceptions in your question.

  • By and large, completion settings are distributed with your shell, not with individual programs. While individual programs could come bundled with completion settings, the same way they're bundled with desktop launchers and menu entries (at least in the major desktop distributions), in practice, in practice, application programmers don't write completion settings, shell developers do.
  • Completion is generally tuned to complete everything that could be useful, not just the most common cases. For example, Inkscape can open JPEG files, even if it's usually not the best program for that, so *.jpg files are included in completions for inkscape. Furthermore, by default, completion includes all files.

For bash, completion settings are distributed in the separate bash-completion package. As of version 2.1, it has no settings for gimp, so completion of arguments to gimp simply offers all files. For inkspace, the completion function is aware of a few options, and completes a large set of image file extensions.

You can display or modify the completion settings in bash with the complete builtin. For example:

$ complete -p inkscape
complete -F _inkscape inkscape
$ type _inkscape
_inkscape is a function
_inkscape () 
    local cur;
    if [[ "$cur" == -* ]]; then
        COMPREPLY=($( compgen -W '-? --help --usage -V --version \
                        -z --without-gui -g --with-gui -f --file= -p --print= \
                        -e --export-png= -d --export-dpi= -a --export-area= \
                        -w --export-width= -h --export-height= -i --export-id= \
                        -j --export-id-only  -t --export-use-hints -b --export-background= \
                        -y --export-background-opacity= -l --export-plain-svg= -s --slideshow' -- $cur ));
        _filedir '@(ai|ani|bmp|cur|dia|eps|gif|ggr|ico|jpe|jpeg|jpg|pbm|pcx|pdf|pgm|png|ppm|pnm|ps|ras|sk|svg|svgz|targa|tga|tif|tiff|txt|wbmp|wmf|xbm|xpm)';
$ complete -p gimp
complete -F _minimal gimp

If you don't like what the _inkscape function does, write your own. For gimp, bash knows of no completion; once you've tried completion at least once, it records _minimal as the completion function. Define your own function (conventionally called _gimp, but it isn't an obligation) if you want something different.

complete -F _gimp gimp
_gimp () {
  _filedir '@(ai|ani|bmp|cur|gif|ggr|ico|jpe|jpeg|jpg|pbm|pcx|pgm|png|ppm|pnm|ras|sk|targa|tga|tif|tiff|wbmp|wmf|xbm|xpm)'

Zsh offers more sophisticated mechanisms such as completing a restricted set, but falling back on a broader set if there are no matches.

  • Nice answer, thanks! Where would I normally want to put these function definitions? In my .bashrc?
    – user39248
    Sep 20, 2015 at 19:52
  • @BenCrowell Yes, .bashrc is the place for your bash customizations, including completion. Sep 20, 2015 at 20:08

You must log in to answer this question.