home > mac > commandHistoryLikeMatlab.txt

Friday, September 9th, 2005

Setting bash command history expansion to use the up arrow like MATLAB

This is one of those simple once you know it but annoying to figure out settings. Via google, I found the solution — add the folling lines to “.inputrc” in your home directory:

"\e[A": history-search-backward
"\e[B": history-search-forward

For extra fun, you can make the command line cycle through options instead of printing them all when you press TAB. Try adding the following line (via macosxhints):

TAB: menu-complete

The jury in my head is still out on if I prefer this behavior. I wish they would just hurry up and decide so I can get used to it.

Update: Note that this takes effect in new terminal windows and new logins, not your current command line session.

Update 2: Steve suggested an alternative approach is to add the following lines to “.profile” or “.bashrc”:

# make bash autocomplete with up 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'

/mac   〆   permalink