4

I am using fedora 25 but I think this is a general behavior on unix system.

When I ctrl+r in a command-line environment I can start to type in and anything I type will get to be matched backward in the invoked command history of the current user. This helps a lot to rapidly find a command and not type it again.

I like to optimize when it comes to my environment, but sometimes when I am fast I found the prompt a bit confusing because everything is white, for instance if I type find during the reverse-i-search, the prompt will output something like that,

(reverse-i-search)`find': find . -type f -name '*.h'

Is there a way to color the part before : ?

4
  • What shell are you using? bash, zsh, etc.? – Abdul Jul 14 '17 at 4:32
  • @Abdul I am using bash – vdegenne Jul 14 '17 at 9:26
  • If you remember what you are looking for, you can do something like history | grep 'pattern' and then type a !nnn, where nnn is the command number listed by history. If you still want color, see stackoverflow.com/questions/20909942/…. There's also grcat superuser.com/questions/602294/… . And if you want an automagical tool for it, you can try history | fzf github.com/junegunn/fzf . None of these uses Ctrl-R, so it's not posted as an answer. – Joe Jul 15 '17 at 9:11
  • Hey @Joe, fzf sets up a Ctrl-R binding for the shell when you run it's install script, effectively replacing the built in reverse-i-search. It colors the search prompt in the exact way OP wanted, so threre's that ;) – Wiesław Herr May 29 '18 at 16:48
0

As https://unix.stackexchange.com/a/352377 suggests, you will have to change source code to do this. Current versions of Bash (up to and including recently released 5.0) can color only filename completion suggestions; i-search always outputs plain text.

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.