I would like to type in the terminal like I do in emacs:

emacs 2019-*subject*

When I hit Tab I get the first match:


What I would like is for it to show me the options such as:

2019-08-03-subject.markdown 2019-bla-bla-subject-predicate.markdown etc...

I looked everywhere online and can't believe this is not a feature.

There are many similar questions asked. The answers don't work like how I want them (shown above). Other solutions I tried: here.

P.S I use Ubuntu 16. This is typical functionality I find in emacs when I am opening files. It would be very convenient.

1 Answer 1


What happens after Tab depends on completion scripts. This answer makes me believe the desired behavior was there for at least one user in 2013, but in 2019 the behavior in my Debian 9 is like you described; possibly the scripts/behavior have changed since.

Besides, Bash chooses a script according to the command typed (first word in the current line). It's not immediately obvious that any single change can affect all completions to provide what you want (I guess the _filedir function is a good start).

Fortunately you can get possible expansions on demand. From man 1 bash (under the READLINE header):

glob-complete-word (M-g)
The word before point is treated as a pattern for pathname expansion, with an asterisk implicitly appended. This pattern is used to generate a list of matching filenames for possible completions.

glob-expand-word (C-x *)
The word before point is treated as a pattern for pathname expansion, and the list of matching filenames is inserted, replacing the word. If a numeric argument is supplied, an asterisk is appended before pathname expansion.

glob-list-expansions (C-x g)
The list of expansions that would have been generated by glob-expand-word is displayed, and the line is redrawn. If a numeric argument is supplied, an asterisk is appended before pathname expansion.

M-g, C-x * and C-x g describe default key bindings. In a more friendly format these are:

  • Meta+g (Alt+g) for glob-complete-word,
  • Ctrl+x, (release Ctrl) * for glob-expand-word (note: * is in fact Shift+8 on my keyboard),
  • Ctrl+x, (release Ctrl) g for glob-list-expansions.

The following code sets these bindings (in case they are missing for whatever reason):

  • for the current shell only:

    # commands to run in Bash
    bind '"\eg":   glob-complete-word'
    bind '"\C-x*": glob-expand-word'
    bind '"\C-xg": glob-list-expansions'
  • or in your permanent config (/etc/inputrc or ~/.inputrc):

    # lines to add
    "\eg":   glob-complete-word
    "\C-x*": glob-expand-word
    "\C-xg": glob-list-expansions

    (note this will only affect new shells, unless you reload).

You will be interested in glob-complete-word or glob-list-expansions. Main differences:

  • glob-complete-word always appends an asterisk, while glob-list-expansions does this conditionally (see the cited manual).
  • If there are many matches then you may need to trigger glob-complete-word twice (i.e. press the key combination twice) before it prints something; this depends on show-all-if-ambiguous, compare the already mentioned answer.
  • If there is just one match then glob-complete-word will perform an actual line completion, while glob-list-expansions will still just display the match.

In your particular case type this:

emacs 2019-*subject*

then Ctrl+x, g.

  • Ctrl+x,g works, although its too many key strokes (with the 2 * and then the keystroke), but works! Thank You very much.
    – Pandian Le
    Oct 11, 2019 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.