Bash – Highlighting text in bash when using reverse history search using Ctrl-R

bashcolorsreadlinesearch

Using Ctrl-R, I can search the history in bash.

But what to do, If I want to highlight the relevant word which has been typed upon by me.

Example:

(reverse-i-search)`mount': sudo mount /dev/sda2 /mnt

In the above reverse search, I want to highlight the world mount from the entire command sudo mount /dev/sda2 /mnt. How to achieve this in bash ?

Best Answer

readline (which bash uses for its line editor) doesn't have that possibility.

zsh does it by default though. By default, it highlights the searched text with underlining, but you can change that. For instance with:

zle_highlight=(isearch:standout)

Or:

zle_highlight=(isearch:fg=red)

(zle is zsh's line editor, like readline is bash's).

Related Question