Since I didn't find a suitable way to color error messages, my solution is to add an additional warning when git returns an error code (!=0).
To do it, add this to your ~/.bashrc
or ~/.bash_profile
# Wrap git. On errors, print an additional line in red.
git(){
command git "$@"
local exitCode=$?
if [ $exitCode -ne 0 ]; then
printf "33[0;31mERROR: git exited with code $exitCode33[0m
"
return $exitCode
fi
}
Here is the result:
Note that coloring stderr in red does not work very well because git logs many things in stderr, not only errors. And some errors are output in standard output.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…