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.

If I have directory containing the files

foo.bar.a.cat
foo.bar.a.hat

and I type ls f+TAB the bash shell autocompletes to ls foo.bar.a.. If I type ls *bar*+ TAB I would like it to autocomplete to *bar*.a.. Is this possible?

This looks similar to the question

How to enable tab completion of wildcards in bash?

but the suggested answer, "it works out of the box for me", does not. I've also tried TAB TAB, with no effect. The command `bash --version gives GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu).

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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

share|improve this answer
    
This does not work (at least for me). Creating the files touch aa ab ac ad and typing ls a followed by alt+* gives the list, but doing it with ls a* does not. The wildcards are the point of the question. –  Hooked May 21 '13 at 15:38
    
@Hooked This works for me on GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu) and GNU bash, version 4.2.0(1)-release (x86_64--netbsd) but not GNU bash, version 4.2.45(2)-release (i386-apple-darwin12.2.0). And by worked, I mean it filed in the text. Will check my conf files to see if I have something extra. –  demure May 21 '13 at 15:44
    
That's strange, why would such a simple thing change from version to version? Any ideas on how to enable it or is it built-in at compile time? –  Hooked May 21 '13 at 15:48
    
@Hooked I'm a bit perplexed too... It also fails on my raspberry pi GNU bash, version 4.2.37(1)-release (arm-unknown-linux-gnueabihf) (raspbian) –  demure May 21 '13 at 15:52
    
@Hooked Found alliterative binding which works on systems where the first had not, for me. –  demure May 21 '13 at 16:18
show 2 more comments

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*).

share|improve this answer
add comment

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.