Take the 2-minute tour ×
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.

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

2 Answers 2

up vote 4 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

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

 
discard

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.