Bash autocomplete like zsh
To get first completion and a listing you can add the following to bashrc
bind 'set show-all-if-ambiguous on'
bind 'TAB:menu-complete'
show-all-if-ambiguous: This alters the default behavior of the completion functions. If set to ‘on’, words which have more than one possible completion cause the matches to be listed immediately instead of ringing the bell. The default value is ‘off’.
see Bash Manual for more information.
Edit:
This doesn't make bash work exactly as zsh tho. Zsh will complete up until the next ambiguous match. Bash will just cycle through all matches.
e.g.
$ ls ~/.ba<tab>
.bashrc .bash_history .bash_profile
- zsh: will complete up until ~/.bash and present a list of matches which handily enables you to append _ and hit
<tab>
again. - bash: will just cycle through all ~/.ba* matches.
I use
bind 'TAB:menu-complete'
to achieve it
Following up on ingkebil's answer, for those that put bind
and set
into inputrc
:
$ tail -n 4 /etc/inputrc
# zsh like completion:
# https://superuser.com/questions/288714/bash-autocomplete-like-zsh
set show-all-if-ambiguous on
TAB:menu-complete
I like keeping my .bashrc
clean.