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.

| improve this question | | | | |

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

| 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.

| improve this answer | | | | |

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

| improve this answer | | | | |

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.