Linux – Globally Coloring the Terminal by Regex

colorconsolelinuxregex

I know many programs use color – (vim, ack, color-ls to name a few) but there are still many cases where you're stuck with black and white.

There are scripts that will color output based on regular expressions (i.e. "make anything that matches 'dog' red") but these must be invoked with pipes – for example: "> cat myfile | color dog red" and this is useless for anything interactive.

What I'm looking for is something that hooks the terminal emulator (or an terminal that actually does this) and colors anything that matches a given regex, independent of the shell or program i'm currently using. If this works with ncurses as well that would be awesome. I have too many monochrome programs and it would be great if I could specify a list of keywords to highlight/color when they appear or are typed.

I use Guake console which probably uses GNOME Terminal, I don't know if GNOME has this feature already.

Best Answer

Short version is: why, yes, you can pipe output from the shell, like any other program.

From there, you can use whatever you like, like, say

$ bash | sed "$(echo -e "s@dog@\e[31mdog\e[0m@g; s@more here@more here@g;")"

Thought I'd add my 'rainbow'. Enjoy:

for((b=0;$b<8;b++)); do echo -ne "\e[4${b}m4$b : "; \
  for((f=0;$f<8;f++)); do echo -ne "\e[3${f}m3${f}"; done; echo -e "\e[0m"; done
Related Topic