Reputation: 131112
In bash is there a quick way to do tab auto-completion based on the middle of a word.
So for example, if I have these files in a directory:
001_apple.txt 002_pear.txt 003_dog.txt
I would like to type the sequence: *d<TAB>
to auto-complete 003_dog.txt.
Can this be done in bash? Is it easier to do in other shells?
Upvotes: 11
Views: 2036
Reputation: 786
I think this is a feature of readline (may even not the default keybinding):
type ls \*middle\*
, then type ctrl-x, *
will replace \*middle\*
with the files that match the pattern.
Upvotes: 0
Reputation: 131112
Looks like zsh does this plus quite a bit more. See: expand-or-complete-prefix and COMPLETE_IN_WORD options.
Fish also does this really nicely out-of-the-box.
Upvotes: 4
Reputation: 73622
ls *d*<TAB>
works in bash. Not sure if that's what Ben meant. ls
could of course be any other command.
Upvotes: 2
Reputation: 17004
Try ESC-g for glob expansion.
And you should always install the bash-completion package (included by default often, but you need to source it in your bash profile script).
Upvotes: 6
Reputation: 1745
You can substitute
`ls *d*`
to achieve the same effect, not quite as convenient as tab-completion however
Upvotes: 0