From fe7e28576ac7044a89b4db3d4357bd219e43ccea Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Sun, 1 Mar 2020 21:22:37 -0500 Subject: Read diff-highlight colors from git config --- pwsh-diff | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pwsh-diff b/pwsh-diff index 77633ed..7ad2478 100755 --- a/pwsh-diff +++ b/pwsh-diff @@ -134,6 +134,23 @@ function Get-GitConfigBoolean { } } +function Get-GitConfigColor { + param ( + [string]$key, + [string]$default + ) + + $color = $(git config --get --type=color "$key") + + # `git config` has a `--default` option, but it doesn't seem to like the + # output from `Get-Color`. + if (!$color) { + $color = Get-Color $default + } + + return $color +} + function Get-VisibleString { param ( [string]$str @@ -343,13 +360,13 @@ function Write-Hunk { $addedTheme = [HighlightTheme]@{ - NormalColor = Get-Color "39" - HighlightColor = Get-Color "39 on_4" + NormalColor = Get-GitConfigColor "color.diff-highlight.newNormal" "green bold" + HighlightColor = Get-GitConfigColor "color.diff-highlight.newHighlight" "green bold on_22" } $removedTheme = [HighlightTheme]@{ - NormalColor = Get-Color "13" - HighlightColor = Get-Color "13 on_5" + NormalColor = Get-GitConfigColor "color.diff-highlight.oldNormal" "red bold" + HighlightColor = Get-GitConfigColor "color.diff-highlight.oldHighlight" "red bold on_52" } $inHunk = $false -- cgit v1.2.3