[英]Git log pretty does not show yellow color on Windows
我將PowerShell與posh-git一起使用。 根據https://app.pluralsight.com/library/courses/git-advanced-tips-tricks/table-of-contents ,以下命令行
git log --pretty='%Cred%h%Creset | %C(yellow)%d%Creset %s %Cgreen(%cr)%Creset %C(cyan)[%an]%Creset'
應該以黃色顯示分支引用。 但是,它不起作用:
確實會顯示紅色,綠色和青色,但不會顯示黃色,這應該為字符串着色(HEAD -> master, origin/master)
。 我檢查了一下,如果我也嘗試將黃色用於日志的其他部分,則它不起作用。 就像PowerShell無法呈現黃色一樣。
這是PluralSight視頻的快照:
在快照中,外殼為zsh,操作系統為Unix或Linux,但是我看不到PowerShell為什么不能顯示黃色的任何原因。
怎么了?
我遇到了同樣的問題,因此我改用了適合我的大膽顏色。
嘗試一下(我也將紅色更改為粗體,因為這樣更可見):
git log --pretty="%C(red bold)%h%Creset | %C(yellow bold)%d%Creset %s %Cgreen(%cr)%Creset %C(cyan)[%an]%Creset"
我使用以下腳本修復了有關Powershell顏色的所有問題。
FixPowershellColors.ps1
reg import $PSScriptRoot\Windows10ConsoleColors.reg
$WindowsPowerShellShortcutDir = "$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell"
$UserPinnedTaskBarDir = "$env:USERPROFILE\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
$sh = New-Object -ComObject WScript.Shell
@(
"Windows PowerShell",
"Windows PowerShell (x86)",
"Windows PowerShell ISE",
"Windows PowerShell ISE (x86)"
) |% {
$ShortcutName = $_
@(
"$WindowsPowerShellShortcutDir",
"$UserPinnedTaskBarDir"
) |? { Test-Path "$_\$ShortcutName.lnk" } |% {
$ShortcutPath = "$_\$ShortcutName.lnk"
$Shortcut = $sh.CreateShortcut($ShortcutPath)
$TargetPath = $Shortcut.TargetPath
del $ShortcutPath
$Shortcut = $sh.CreateShortcut($ShortcutPath)
$Shortcut.TargetPath = $TargetPath
$Shortcut.Save()
}
}
"Reopen PowerShell console to see the changes"
它需要第一行來更新Windows10ConsoleColors.reg
的Powershell顏色,其余的專用於刷新各種Powershell快捷方式。
Windows10ConsoleColors.reg
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Console]
"ColorTable00"=dword:000c0c0c
"ColorTable01"=dword:00c50f1f
"ColorTable02"=dword:0013a10e
"ColorTable03"=dword:00c19c00
"ColorTable04"=dword:000037da
"ColorTable05"=dword:00881798
"ColorTable06"=dword:003a96dd
"ColorTable07"=dword:00cccccc
"ColorTable08"=dword:00767676
"ColorTable09"=dword:00e74860
"ColorTable10"=dword:0016c60c
"ColorTable11"=dword:00f9f1a5
"ColorTable12"=dword:003b78ff
"ColorTable13"=dword:00b4009e
"ColorTable14"=dword:0061d6d6
"ColorTable15"=dword:00f2f2f2
因此,只要您的Powershell快捷方式位於眾所周知的位置,腳本就會對其進行全部更新,之后您只需要重新打開控制台窗口即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.