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.