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.

Since tab completion became a standard feature in shells I have been a very happy user of it. I even like Bash's intelligent completion (where it only searches for PDF files, if I type evince foo<TAB>) - as long as it guesses correctly.

It ruins an otherwise happy day when Bash uses its intelligent completion to refuse completing.

Today I wanted to:

tar xvf centos5.8_x86_1.ova

So I entered:

tar xvf cent<TAB>

and Bash refuses to complete the path because .ova-files is not what you usually use with tar.

I know I can uninstall the bash-completion package to remove the intelligent completion. But can I have my cake and eat it too?

Can I ask bash to use intelligent completion first, and if that fails, then use non-intelligent completion?

share|improve this question
1  
<spam> Zsh can do it. </spam> –  Gilles Mar 30 at 20:47

2 Answers 2

bash completetion is an extension of bash's standard completion and is itself a bash program. So if you want to change how the program acts, just change it. This is free software, you are free to do it. For the specific case of the tar command, the file is /usr/share/bash-completion/completions/tar. For tar to autocomplete a file with extension ova, just add it to the line

local tars='@(@(tar|gem|spkg)?(.@(Z|[gx]z|bz?(2)|lzma))|t@([glx]z|bz?(2)))'

so it says

local tars='@(@(tar|gem|spkg|ova)?(.@(Z|[gx]z|bz?(2)|lzma))|t@([glx]z|bz?(2)))'

Note that this is the path and the code existing for Debian Wheezy (current stable version). A different distro or version may have a different code but the idea is the same. Open the code and adjust it to do what you want it to do.

Edit: I just noticed that the question was about every time that it doesn't find a match and not only the specific case of adding ova to tar. Maybe it can still be useful to someone, to know where they can look for the source.

share|improve this answer
    
Modifying files in /usr that are owned by the package manager is a good way to induce a nasty shock on upgrade. Better: override the packaged configuration. –  Chris Down Mar 31 at 3:10
    
@ChrisDown and how would you do that? I'm still looking for the clean .bashrc solution. –  Clayton Stanley Mar 31 at 5:16

The following should turn on normal bash completion after all 'intelligent' completions have failed for the programs tar, vim and emacs:

compopt -o bashdefault tar vim emacs

see also the relevant page in the online bash manual.

Caveat: you get the normal behavior for the type of completion (commands/filenames/usernames etc.) defined by the intelligent completion for the command at hand, for example, the completion for service will not complete filenames even if you call complete -o bashdefault service.

In this and other cases where the intelligent autocompletion fails, you can always press Alt-/ (or M-/ in the bash manual's notation) to complete filenames almost in the same way that TAB works if intelligent completion is disabled (almost the same way in the sense that M-/ does not complete patterns like *.txt). See here for key sequences for other types of completions such as command and usernames.

share|improve this answer

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.