Tuesday, November 11, 2008

Bash Search History

I'm kind of an old school command line hacker, but I've got to face up to the fact that the rest of the world seems to be moving on from the ksh. As such my previous super powers for editing command histories with vi commands (esc-k, /, etc) are going to have to be retired. As the rest of the planet has embraced bash, I've found myself struggling with the fact that crtl-r only lets me get the previous command.
The bask docs suggest that Meta-p will then scroll back through those commands, but esc, alt and apple keys are all major fail for meta on my mac.

However I have found an acceptable solution. If you create the following .inputrc file then you can start typing any command, then the up/down arrows will allow you to scroll through previous commands that started the same way.

i.e. type vi then up arrow, up arrow will find the last but 2 vi commands you typed.

# search history via arrows - .inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward

No comments: