alternate way to trigger reverse-i-search without pressing ctrl+r in bash

bash, history, keyboard-shortcuts, search

Solution

The reverse-i-search function is actually a readline function (reverse-search-history) and not a bash builtin function (man builtin or see builtin commands in the bash reference manual). To my knowledge there is no way to call a readline function outside of binding it to a key.

You can see all the readline key binding to these function using "`bind -l -p`". The list of bindable readline commands can be found in the reference manual as well.

You can always use the `history` command to get a list of the history and use `grep` to find what you are looking for. Myself I find this to be useful:

alias hists="history | grep -v '^ *[0-9]* *hists' | grep $@"

When I run `hists something` I get a list of all the commands that matches `something`. All I have to do is then do !# to run the command. For example:

bash-3.2$ hists emacs
   30 emacs
  128 emacs
  129 emacs
  204 emacs
  310 emacs .bash_history
  324 emacs Documents/todo.txt
bash-3.2$ !324

It's not exactly what you are looking for but it's as close as I can make it.

Problem

The reverse-i-search facility in bash is useful, but it is unlike most other bash commands in that it seems to be bound to a keybinding (Ctrl + R). How can a user trigger this facility using an alias or typed-in command instead?

Original source