Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable tab-completion of command line switches in bash?

With bash, I can complete a command with TAB. Normally, it should also complete the command line switches: e.g. when I typed:

java -

it should show me the possibilities. It does not. How can I enable this preview?

See also Surprise! the shell suggests command line switches

like image 694
Burkhard Avatar asked Apr 22 '09 12:04

Burkhard


People also ask

Does bash have tab completion?

Bash completion is a functionality through which Bash helps users type their commands more quickly and easily. It does this by presenting possible options when users press the Tab key while typing a command.

How does tab completion work bash?

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.


2 Answers

You need to have bash_completion installed and then just add . /etc/bash_completion to your .bashrc.

like image 77
dunkyp Avatar answered Sep 19 '22 06:09

dunkyp


Depending on what Linux flavor you're using, you may want to add a package. For Fedora and related distributions, you need to add the separate package bash-completion to get this to work. I wouldn't be surprised if other distributions had this packaged as an optional 2nd package that you need to add in addition to the bash package.

like image 39
Eddie Avatar answered Sep 18 '22 06:09

Eddie