5

I can enter a command:

$ echo hello
hello

Then search for it with Ctrl+R:

(reverse-i-search)`h': echo hello

Then sometimes the search will fail:

(failed reverse-i-search)`hz': echo hello

Can I somehow color the "failed reverse-i-search" part of the display? I would prefer if it was red text to contrast with normal white text. That way I can quickly tell that a search has failed.

1

Based on current version of Bash (4.4), the message "failed reverse-i-search" is generated in the same place & in the same way as "reverse-i-search" making them indistinguishable for any feature that might change it's color.

Essentially to achieve exactly what you ask is necessary to modify the bash source code. (file ./lib/readline/isearch.c around line 180) http://git.savannah.gnu.org/cgit/bash.git/tree/lib/readline/isearch.c

The alternative would be to enable "visual bell" for your terminal because when search fails, then there is a "Ding the bell" action done which can be an audio or visual event on your terminal. (see file ./lib/readline/isearch.c line 715)

| improve this answer | |
1

As czvtools noted, "failed reverse-i-search" fires a bell. You can create a visual bell instead of the regular one. Create a file "xterm-vb.terminfo":

xterm-vb|red visible bell,
# \e7                   save current cursor position
# \e[40A                up 40 lines
# \e[80C                move right 80 spaces
# \e[4D                 move left 4 spaces
# \e[5;30;41mERROR\e[m  bright background; foreground black; background red
# \e8                   restore cursor to position of last save_cursor
  flash=\e7\e[40A\e[80C\e[4D\e[5;30;41mERROR\e[m\e8,
  use=xterm,

Compile and install the file:

tic xterm-vb.terminfo

Add line to "~/.profile" or similar:

TERM=xterm-vb

Add line to "~/.inputrc":

set bell-style visible
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.