Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: unmatched '



At 14:45 -0800 09 Mar 2018, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
Why are you putting stuff like that file in /etc/ in the first place?

Heck, not me!  That's stock Debian, I'd not create a directory like that on pain of damnation.  Debian should not allow it either, IMHO.

No, that file is not included in any Debian package:

https://packages.debian.org/search?searchon=contents&keywords=DSHR&mode=filename&suite=stable&arch=any

    ccolor=33      # Start with yellow, then blue, magenta, cyan.
    for file in "$@"; do
        # We colorize the already selected lines here:
        grepstring="$grepstring | GREP_COLOR='01;'"$ccolor" grep $wwild $ccase --color=always \"$file\""
        (( ccolor++ )) # Next color.
    done

... so I'm filtering and colorizing however many arguments there are to the command, so each iteration must (?) begin with the pipe.  And the final string:

Perhaps something like the following? This doesn't include the doing the find(1), instead it's designed to get the text to search on STDIN. It also doesn't use the $wwild or $ccase variables, which I didn't see defined anywhere. But that would be easy to add.

No use of eval here. Besides being safer, that also tends to be more readable; although the use of recursion here cuts down on that improvement.

Despite having zsh on the #! line, this would work with bash as well.

#!/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 "$@"



Messages sorted by: Reverse Date, Date, Thread, Author