zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: unmatched '
Date: Sat, 10 Mar 2018 09:40:18 -0800	[thread overview]
Message-ID: <72253ae6-ec4b-0f00-a7f5-9d917afdb565@eastlink.ca> (raw)
In-Reply-To: <dc5c8ba7-290f-dee4-2d7c-7dcf09059005@eastlink.ca>

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 "$@"; do
         foo=( `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.



      reply	other threads:[~2018-03-10 18:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 17:50 Ray Andrews
2018-03-09 20:23 ` Bart Schaefer
2018-03-09 22:45   ` Ray Andrews
2018-03-09 23:12     ` Ray Andrews
2018-03-10  3:20     ` Aaron Schrab
2018-03-10  3:51       ` Ray Andrews
2018-03-10 17:40         ` Ray Andrews [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72253ae6-ec4b-0f00-a7f5-9d917afdb565@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).