10

Auto-completion in bash (with Tab) works on folders, but not with files.

  • I'm running Ubuntu 13.10
  • I haven't touched my .bashrc file

This is how the bottom part of the .bashrc file looks, with the bash-completion part installed and updated:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Any ideas?

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
Finn
  • 168
  • 2
  • 3
  • 15

3 Answers3

21

The third party "bash_completion" package (not to be confused with bash or its native completion) can sometimes be hard to predict.

  1. Some commands are specifically set up to not never complete files, like cd
  2. Some commands will refuse to complete certain filenames, because bash_completion doesn't realize the program handles them, like mplayer.
  3. Some commands are just buggy, especially when paths contain spaces and other characters, like for scp.

If you're ever in a situation where bash_completion isn't being helpful, you can use M-/ (aka Alt + /) to use bash's native filename completion instead.

If a command is frequently giving you trouble, you can disable bash_completion for this command using complete -r thatcommand at the end of your .bashrc.

that other guy
  • 116,971
  • 11
  • 170
  • 194
  • Using bash's native completion worked for me! Odd that Tab somehow does not do the same thing, seeing as it's not remapped to something else. For now, this is solved for me, thank you all for taking your time writing your answers. – Finn Feb 26 '14 at 07:22
  • 1
    @Finn do you have an example of a command line where you're hitting tab and it's not completing what you expect? Keep in mind that the command itself and the parameters are relevant too, since bash_completion uses them to determine what to complete. – that other guy Feb 26 '14 at 07:26
  • 1
    +1 for "complete -r". Cygwin bash stopped autocompleting with tab when adding \ before a space and this did the trick. – Nick Apr 26 '15 at 18:18
  • You've cited ```mplayer``` as an example of broken behaviour, but your solution, ```complete -r mplayer``` does not work. – burito Mar 19 '18 at 01:00
  • @burito Do you have a test case? – that other guy Mar 19 '18 at 01:44
2

.bashrc file seems ok so the problem probably is in one of the bash_completion files.

I suggest you backup the files and try to replace them with these:

for /etc/bash_completion:

http://pastebin.com/0HWHsbyR

for /usr/share/bash-completion/bash_completion:

http://pastebin.com/c49KrbXT

that are the standard completion files for ubuntu 13.10. Restart the console before checking if it worked.

Troveldom
  • 356
  • 1
  • 10
  • Jus tried this, and it didn't really affect anything, as far as I can tell. I also tried "reinstalling" (purged and install) bash-completion to no avail. – Finn Feb 26 '14 at 07:19
0

One possible cause for this is a file named !. Some default bash-completion setups have a bug when such a file exists. You can remove the file or patch /usr/share/bash-completion/bash_completion as shown in the bug link.

Chris Povirk
  • 3,738
  • 3
  • 29
  • 47