简体   繁体   English

ZSH中的管道正在从Git日志输出中剥离颜色

[英]Pipe in ZSH is stripping colors from Git log output

I'm trying to utilize GRB's git helpers ( https://github.com/garybernhardt/dotfiles/blob/master/.githelpers ) for pretty printing my git log. 我正在尝试利用GRB的git助手( https://github.com/garybernhardt/dotfiles/blob/master/.githelpers )来打印我的git日志。

The git log --graph --pretty="tformat:${LOG_FORMAT}" command from line #62 works just fine; 第62行的git log --graph --pretty="tformat:${LOG_FORMAT}"命令工作得很好; printing with colors in iTerm. 在iTerm中使用颜色打印。 But as soon as it's piped to pretty_git_format there are no colors displayed. 但是一旦它pretty_git_format送到pretty_git_format ,就没有显示颜色。

This has been working for several years until just a few weeks ago. 这已经持续了几年,直到几周前。 Was there a change in zsh that I now need to configure differently? 我现在需要配置不同的zsh有变化吗?

I'm using iTerm2 and zsh version zsh 5.4.2 (x86_64-apple-darwin16.7.0). 我正在使用iTerm2和zsh版本zsh 5.4.2(x86_64-apple-darwin16.7.0)。

The default behavior for git is to produce color if the output is being printed to a terminal (directly or through a git-spawned pager). git的默认行为是在输出被打印到终端(直接或通过git生成的寻呼机)时产生颜色。 When your output goes somewhere else, like a pipe, git turns off colors. 当你的输出到达其他地方时,就像管道一样,git会关闭颜色。

You can set the color.ui option to always on the command line like this: git -c color.ui=always log --graph --pretty="tformat:${LOG_FORMAT}" (and yes, that's where the -c option goes). 您可以将color.ui选项设置为always在命令行上,如下所示: git -c color.ui=always log --graph --pretty="tformat:${LOG_FORMAT}" (是的,这就是-c选项去)。 If you want to do this frequently, it can be done with a shell alias in .gitconfig . 如果您想经常这样做,可以使用.gitconfig的shell别名来.gitconfig

While you can set this in your .gitconfig as well, you probably don't want to. 虽然您也可以.gitconfig设置它,但您可能不希望这样。 Most external programs assume color is turned off, and you can break other parts of git, as well as tools like editor integrations, if you set this in .gitconfig . 大多数外部程序都假设颜色已关闭,如果你在.gitconfig设置它,你可以打破git的其他部分,以及编辑器集成等工具。

This started happening to me today, after updating to OSX High Sierra and updating my homebrew packages. 在更新到OSX High Sierra并更新我的自制程序包之后,今天就开始发生这种情况了。

I suspect it is something to do with the latest Git version (2.15.0), as those release notes mention changing how the git log colors work: 我怀疑它与最新的Git版本(2.15.0)有关,因为这些发行说明提到了改变git log颜色的工作方式:

Fixes since v2.14
-----------------

 * "%C(color name)" in the pretty print format always produced ANSI
   color escape codes, which was an early design mistake.  They now
   honor the configuration (e.g. "color.ui = never") and also tty-ness
   of the output medium.

So I think Brian's solution is probably the best one, but I do note that it does seem to affect the column formatting of pretty_git_format , which I mentioned in a comment above. 所以我认为Brian的解决方案可能是最好的解决方案,但我注意到它确实会影响pretty_git_format的列格式,我在上面的评论中提到过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM