How to colorify git errors, warnings and fatal messages?

前端 未结 4 1922
傲寒
傲寒 2020-12-01 13:59

When troubleshooting git issues of users, I keep running into people not noticing error/warning messages from git, and then burning their fingers. Is there any way to colori

4条回答
  •  执笔经年
    2020-12-01 14:56

    There is no git buit-in way to do that. Git just prints errors to STDERR and doesn’t care about the fatality of the error or anything. What you can do is color STDERR red. How to do this has been asked on on ServerFault: https://serverfault.com/questions/59262/bash-print-stderr-in-red-color

    There are three basic options:

    1. Run your command like this:

      *git-command* 2> >(while read line; do echo -e "\e[01;31m$line\e[0m" >&2; done)
      
    2. Use a wrapper script (See ServeFault for those), and run commands like

      mywrapper *git-command*
      
    3. Install stderred. This will allow you to make the effect permanent, without modifying your command line. Not sure whether this will work on windows, though.

提交回复
热议问题