Last Updated: January 28, 2019
·
2.947K
· calamari

Pimp your bash with menu-completion

If you start typing in your terminal of choice (mine is btw iTerm2) you may be annoyed if you type the first two letters of the command only and just want to hit return, because you are simply feeling lucky.

This is how it might look at the moment:

$ ph
php         php-config  phpize  

How can I get lucky?

Open or create the file ~/.inputrc. Within this file add the following line – you will bind the menu-completion method to the TAB key:

TAB: menu-complete

With this simple line (and a restart of your bash) you get the following behavior. If you start type ph and then hit TAB your bash will gladly auto complete your input to the first item in the list of suggestions – if we stick to our exemple: php.

Hitting TAB multiple times allows you to switch between every item in the list (so php, php-config, phpize and finally back to ph).

Cool, huh?

If you are a true explorer, there is also a lot more to explore in your man hash.