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.

3 Answers 3


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() {"...

  • 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.
    – Etheryte
    Commented Aug 27, 2012 at 17:43
  • One drawback with this method is that history will show grc at the start of every command. Commented Jul 1, 2015 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.


Consider using grc.zsh that's part of grc which can be found here. It has aliases for all supported commands.
See this Stackoverflow answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .