Bash – Make BASH’s Tab Completion Fill In First Match

autocompletebash

Is there any way to make BASH fill in the first match when I press TAB, kind of like the Windows command prompt?

(It should still display the list of matches, but it should cycle through them when I keep on pressing tab.)

i.e. the goal here is to be able to fill in any match with only the TAB key, given enough presses — like in Windows.

Best Answer

Add the following to your .inputrc file, (exact location varies between systems):

"\C-i": menu-complete

This maps TAB to menu-complete, which auto-completes the first match.

Then add (or uncomment) show-all-if-ambiguous, this shows the list of possible completions on the first TAB press.

For example, in your (possibly) .inputrc file:

# On RHEL 8.3 - $HOME/.inputrc
set show-all-if-ambiguous on
"\C-i": menu-complete

Alternatively, you can set menu-complete per session (without editing .inputrc) by doing

bind '"\C-i" menu-complete'