Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash will not auto-complete (Tab) with files

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?

like image 953
Finn Avatar asked Feb 26 '14 06:02

Finn


People also ask

Does bash have tab completion?

The programmable completion feature in Bash permits typing a partial command, then pressing the [Tab] key to auto-complete the command sequence. [1] If multiple completions are possible, then [Tab] lists them all. Let's see how it works. Tab completion also works for variables and path names.

How do you autocomplete in Linux?

Command auto-completion is available when using the CLI shell. You can set up CLI command auto-completion in your operating system using the kollacli command command. This command generates a script you can save to the operating system. Copy and paste the output to a file, for example a file named /etc/bash_completion.

How does Tab autocomplete work?

Using autocomplete is as simple as pressing the [TAB] and the active command line options will fill-in. If more than one option is available, you can hit [TAB] twice to display all possible choices and continue typing until there is only one matching choice left.


1 Answers

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.

like image 185
that other guy Avatar answered Nov 15 '22 19:11

that other guy