Color regex matches - without dropping misses

后端 未结 7 908
日久生厌
日久生厌 2021-02-07 02:21

When using grep --color=always I can get pretty color highlighting for regex matches.

However, grep only returns lines with at least one match.

7条回答
  •  悲哀的现实
    2021-02-07 02:47

    This little function works well in my ZShell:

    function color_grep {
        sed s/$1/$fg[yellow]$1$terminfo[sgr0]/g
    }
    

    (Needs

    autoload colors zsh/terminfo
    

    )

    Maybe you can do something similar?

    Edit: Sorry, this won't work with regexes. You will have to tweak it a bit ...

提交回复
热议问题