Sunday, March 4, 2007

Upstairs, Downstairs

Navigating the console command history can be tedious at times. One simple configuration I find very useful is binding the up/down keys to the backward/forward search functions of libreadline, by adding the following lines to ~/.inputrc:

$if mode=emacs

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

With this, just typing the first few characters of a command and hitting the up arrow key, will bring the previous command that starts with the already typed text. Now hitting up/down allows one to pick the right command from the history (hit ENTER to execute the line, or any other key to modify it).

This seems to work with any console based program that uses libreadline for keyboard input.

No comments:

Post a Comment