Tuesday, March 22, 2011

Bash history autocomplete galore

Add the following lines to the end of .bashrc

# make bash autocomplete with up/down arrow
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'

# make tab cycle through commands instead of listing
bind '"\t":menu-complete'

Now by pressing arrow up/down bash will autocomplete based on your command line history, while pressing TAB will cycle through commands, directories and files names.

Very handy, if you ask me, but it is a love/hate thing. Some people will despise this behaviour others won't know how they could have lived without it.

*** Bonus ***

If you are part of the sudo group, add this lines too to .bashrc and you'll be able to autocomplete after typing sudo.

# sudo autocompletion
if [ "$PS1" ]; then
    complete -cf sudo

Happy autocompleting!


No comments:

Post a Comment