On 09/03/18 07:51 PM, Ray Andrews wrote:
On 09/03/18 07:20 PM, Aaron Schrab wrote:#!/bin/zsh -u # Multi-color grep __mcgrep() { local color=$1; shift local pattern="$1"; shift if [[ $# = 0 ]]; then # No more patterns, just pass through the input cat else __mcgrep $((color + 1)) "$@" fi | GREP_COLOR="01;$color" grep --color=always "$pattern" } # Start with yellow, then blue, magenta, cyan. __mcgrep 33 "$@"Thanks, that's interesting, I'll experiment with it tomorrow.
That sure got me thinking. At the very least I can drop 'eval' by looping: for file in "$@"; dofoo=( `print -l $foo | GREP_COLOR='01;'$ccolor grep --color=always $file` ) bar=( `print -l $bar | GREP_COLOR='01;'$ccolor grep --color=always $file` )
(( ccolor++ )) # Next color. done... it seems that one pipe at a time is fine, so rather than create the chain of pipes ahead of time, and try to pass it via $grepstring, if I just loop, everything is fine. My entire function ends up 600 bytes shorter and the whole thing is much easier to read.