To be precise, we are talking about the “readline Emacs editing mode” keyboard shortcuts. They work in a wide variety of CLI tools, notably your bash or zsh shell. What most people don’t know is, they also work on macOS (née OS X) in any text input field.
This handy piece of code colors errors and warnings in make output.
(put it in your .bash_profile)
ccred=$(echo -e ???\033[0;31m")
ccyellow=$(echo -e "\033[0;33m")
ccend=$(echo -e "\033[0m")
/usr/bin/make "$@" 2>&1 | sed -E -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&$ccend%g??? -e ???/[Ww]arning[: ]/ s%$pathpat%$ccyellow&$ccend%g???
An alternative would be to install colormake and use that instead of the normal make command.
grep is a useful little *nix command line utility that makes it easy to search for strings in files. The real beauty comes when you start using it with pipes. One thing that kind of bothered me since I started using it, that it didn’t highlight the string you where searching for in it’s output.
Turns out, this can be accomplished very easily (should really just have reade the man page 😉 ).
Put the following in your shell startup script (/home/flo/.bashrc in my case)
Now that was simple wasn’t it (though you’ll have to re-log in to make it work or at least spawn another shell process, so the startup file gets sourced) 🙂
But now if you followed my tip and started using pipes like mad, after applying this tip, you’ll quickly encounter that the colors are gone again. To hand over colors to say the often used less program you have to make an alias that hands grep the --color=always option (don’t put this in GREP_OPTIONS it tends to break things!) and call less with the -R option.
Or simpler, just add the following to your shell startup script:
alias cgrep='grep --color=always'