Context specific history at the bash prompt
One change I made recently to my .profile is this:
# up & down map to history search once a command has been started. bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward'
These two bind command change the way that the up and down arrow keys work once you start typing a command to only search the history for lines that start with what you’ve typed so far.
This means that I type, say, git and then press ↑ & ↓ to go through all the times I’ve typed a git command without having to go through all the other commands.
It’s quite handy and I find it easier to use than ctrl+r.
5 thoughts on “Context specific history at the bash prompt”
Awesome. But bind doesn't work in zsh I found. zsh users can use:
to achieve the same.
You can also do this with a .inputrc file, along with making it case insensitive and provide a list the possible completion values. The I got this from a post by Jude Robinson here on coderwall.com
I prefer to map this to Shift+Up (
"\e[1;2A") instead, because when I work with other people, they were getting confused by the way the Up arrow was working. Some terminal emulators come with Shift+Up defined, but on Mac OS X Terminal, I had to define it in the Terminal preferences. (Actually, I've scripted the keybindings, but it was a lot of work: https://github.com/boochtek/mac_config/blob/master/terminal.sh)
It's worth checking
/etc/inputrcon your system, as there are usually suggestions in there that can make working in the terminal more pleasant.
I like using:
which make Page Up and Page Down search through the history, instead of ↑ and ↓ as you describe. These are enabled by default nowadays on Fedora (see https://bugzilla.redhat.com/show_bug.cgi?id=500989).
Comments are closed.