2017-10-21 135 views
2

我試圖利用GRB的git幫助程序(https://github.com/garybernhardt/dotfiles/blob/master/.githelpers)打印我的git日誌。ZSH中的管道正在從Git日誌輸出中剝離顏色

來自#62行的git log --graph --pretty="tformat:${LOG_FORMAT}"命令工作正常;在iTerm中用顏色打印。但是,只要將其連接到pretty_git_format,就不會顯示任何顏色。

這直到幾個星期前一直工作了幾年。 zsh中是否有更改,我現在需要配置不同?

我使用iTerm2和zsh版本zsh 5.4.2(x86_64-apple-darwin16.7.0)。

+0

您是否檢查您的尋呼機是否離開原始輸出(以保留顏色)? 'git config --global core.pager'less -R'':https://unix.stackexchange.com/a/64932/7490 – VonC

+0

不是這樣。即使我只是'git log --graph --pretty =「tformat:$ {LOG_FORMAT}」|貓'它打印沒有顏色。 –

回答

2

git的默認行爲是在輸出打印到終端(直接或通過git-spawned pager)時產生顏色。當你的輸出到別的地方,比如管道,git關掉顏色。

您可以像這樣在命令行上設置color.ui選項alwaysgit -c color.ui=always log --graph --pretty="tformat:${LOG_FORMAT}"(是的,這也正是-c選項進入)。如果你想經常這樣做,可以用.gitconfig中的shell別名來完成。

雖然你可以也設置在你的.gitconfig以及,你可能不想。如果你在.gitconfig中設置了這個功能,大多數外部程序假定顏色關閉,你可以打破git的其他部分,以及編輯器集成等工具。

+1

謝謝。這工作。但我想知道爲什麼現在需要這樣做,過去不是這樣。 –

+0

@MatthewBoston - 我有這個問題。添加'-c color.ui = always'就像你說的那樣工作,但似乎也影響'pretty_git_format'中的列格式。你也找到了嗎? – asgeo1

1

今天開始發生在我更新到OSX High Sierra並更新我的自制軟件包之後。

我懷疑這是值得做的最新的Git版本(2.15.0),因爲這些release notes提改變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. 

所以我覺得布萊恩的解決方案可能是最好的一個,但我確實注意到它似乎影響了上面註釋中提到的pretty_git_format的列格式。