I have a question similar to this one, but different: I want bash to use a glob expansion in auto-completion, if possible. For example, I would like
$ ls *2.<TAB>
To give me:
$ ls mydoc2.
mydoc2.pdf mydoc2.tex mydoc2.txt
I face this situation quite often. In the above example I used the short prefix “mydoc,” but the actual ones are often quite long. Is this possible?
I understand *2.*
would expand with C-x*
, but that's a different function, which isn't suitable in this situation (because I need to choose just one file from the list of the files that match the glob).
Best Answer
The best method to simulate this auto-completion behavior is to enable the
show-all-if-ambiguous
readline variable (to display the possible completions if more than one match is found), then invoke the completion with theglob-complete-word
readline command (to perform the glob pathname expansion).