Bind the bash history methods
Bash is an awesome shell and also very configurable. Some of bash’s build-in functions are not binded to keys, some of which REALLY should be!
Bash has two very useful functions used for searching your bash history:
So the question is how do we bind them. I bound them to Control-<up> and Control-<down>. To do this add the following lines to your ~/.inputrc file:
Note: To test it out you can use the bind command for your current shell:
bindÂ "\e[1;5A": history-search-backward
If you want to use a different key combination then you can use the ‘read’ command to print it out, for example runnding the command read, then hitting control-<up>:ï»¿
matt@wks1005847 ~ $ read
When we bind the key we replace the ‘^[‘ with a ‘\e’ as ‘^[‘ can match the <Escape> key.
3 Replies to “Bind the bash history methods”
Cool. Fedora does this out of the box with Pg-Up/Down 🙂
What’s the difference between this and just the default C-s / C-r
Well the reverse look up allows you to do a reverse search, but if you match something you can’t go back to a further back match.
I know zsh allows this behavior with its reverse-lookup.
This allows you to continue matching the command/text you started writing, if that makes sense. Plus I think C-/ is useful as and are already history commands, so this is a good extension.
Further C-s on my machine suspends my terminal, so.. yeah.
@Chris: My Fedora machine doesn’t have this mapped, maybe I need to upgrade the 14 then check it out, thanks 🙂