How do I let bash autocomplete wildcards?

You want either:

insert-completions

ALT* for 'insert all completions'

With this, a dir containing files name 'aa ab ac ad'
ls a* followed by alt + * would complete to ls aa ab ac ad

Man page entry on binding:

insert-completions (M-*)

Insert all completions of the text before point that would have been generated by possible-completions.

glob-expand-word

On some systems the above will not work with wildchars, the following does work on such systems for me:

ctrlx, * (a two stroke combo)

Example: I populated a dir with:

touch {a,b,c,d,e,f}{1,2,3,4,5,6,7,8,9,0}00{a,b,c,d,f,e}

I then ls *100* followed by ctrl + x, *, which turns my readline into:

ls a100a a100b a100c a100d a100e a100f b100a b100b b100c b100d b100e b100f c100a c100b c100c c100d c100e c100f d100a d100b d100c d100d d100e d100f e100a e100b e100c e100d e100e e100f f100a f100b f100c f100d f100e f100f

Man page entry for binding:

glob-expand-word (C-x *)

The word before point is treated as a pattern for pathname expansion, and the list of matching file names is inserted, replacing the word. If a numeric argument is supplied, a ‘*’ is appended before pathname expansion.

Man Page


Try adding this to ~/.inputrc:

set show-all-if-ambiguous on

show-all-if-ambiguous makes pressing tab once (instead of twice) list all completions. It also makes the first tab press insert shared prefixes of glob expressions.

$ touch 1.0.{1,2}
$ echo *0* # I pressed tab once here
1.0.1  1.0.2
$ echo 1.0.

glob-complete-word (\eg) would also complete *0 (without * at the end) to 1.0.. It also completes for example /System/Library/Launch*/*Finde to /System/Library/LaunchAgents/com.apple.Finder.plist.

If you wanted to convert * to 1.0.1 1.0.2 in the example above, use either insert-completions (\e*) or glob-expand-word (\C-x*).


This problem is caused by bugs in the "bash-completion" package.

When the package is not installed bash does it's default completion, this is a pretty good generalised file name completion engine.

The "bash-completion" package is supposed to look at the rest of the line and be "smart" about the lists it generates. However, it's unable to duplicate the "glob" expansion successfully.

Personally, I think the package is trying far too hard and ends up being usable only by the "dumbest common user".

Though, before deleting it you may want to check the top of the file "/usr/share/bash-completion/bash_completion" for useful additions to your .bashrc for 'gross tuning' of the built-in bash completion.

BTW: It has over a hundred logged bugs ... https://bugs.debian.org/cgi-bin/pkgreport.cgi?package=bash-completion