How can I keep the color output of git status when piping it through grep?

How can I keep the color output of git status when piping it through grep?

I'm trying to compress the output of git status a bit, for a "system status" script that runs whenever I log in to an ssh session. I'm hoping it'll nag at me and encourage me to commit more often!

git status | grep -v "git add\|git checkout\|no changes added"

Sadly it loses the coloring; any modified files are shown in the default font color, not red.

I've tried adding --color=never to the grep command, but that didn't make a difference, so I assume git status isn't adding color codes because of the pipe. Since a few commands in linux have --color=always to get over this, I tried adding that to git, but it just complained about an unknown option.

Thanks

答案1

I've discovered that you can add color options to the .git/config file in the project directory. This did exactly what I wanted:

[color]
status = always

相关内容