Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've recently installed grc (generic colorizer) to my system via MacPorts, giving me the ability to get colorized output for plenty of commands which by default don't support it (see screenshot below). Example of grc with traceroute.
I would like to make using grc automatic, however not for specific commands, but for every command. I use zsh as my shell.

Essentially whenever I execute command -parameter 1 2 3 I would like it to automatically be executed as grc command -parameter 1 2 3.
I'm not looking to use aliases, for example traceroute alias to grc traceroute, as I'm adding more and more commands for grc to colorize.

I've looked into preexec and precmd configurations for .zshrc, but I haven't found a way to achieve what I'm looking for.

share|improve this question
up vote 5 down vote accepted

You could do it by redefining the accept-line widget:

add-grc() { [[ $BUFFER = grc* ]] || BUFFER="grc $BUFFER"; zle .$WIDGET "$@"; }
zle -N accept-line add-grc

However, it could cause problem for commands like "for i (..)", "var=x", "f() {"...

share|improve this answer
Good point. I couldn't think of any problems this solution could create myself, but you're right on this behalf. Thank you for your time. – Nit Aug 27 '12 at 17:43
One drawback with this method is that history will show grc at the start of every command. – joeytwiddle Jul 1 '15 at 1:23

Other alternative. Same kind of potential problems:

TRAPDEBUG() { eval "grc $ZSH_DEBUG_CMD"; setopt errexit; }

I would use an "alias" for every command that needs "grc" instead of trying to figure out exceptions for the solutions posted here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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