Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Arian
dotfiles
Commits
76c4989e
Commit
76c4989e
authored
Oct 16, 2018
by
Arian Stolwijk
Browse files
Use pygmentize for git diffs
parent
6cb0557b
Pipeline
#15883
failed with stages
in 1 minute and 19 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
0 deletions
+71
-0
.gitconfig
.gitconfig
+1
-0
git-hldiff-driver
git-hldiff-driver
+6
-0
hldiff
hldiff
+62
-0
pygmentize-term
pygmentize-term
+2
-0
No files found.
.gitconfig
View file @
76c4989e
...
...
@@ -27,6 +27,7 @@
rebase
=
true
[diff]
tool
=
meld
external
=
git-hldiff-driver
[difftool]
prompt
=
false
[difftool "meld"]
...
...
git-hldiff-driver
0 → 100755
View file @
76c4989e
#!/bin/bash
set
-euo
pipefail
# Program suitable for GIT_EXTERNAL_DIFF, which will syntax-highlight differences.
hldiff
-u
"
$2
"
"
$5
"
||
true
hldiff
0 → 100755
View file @
76c4989e
#!/bin/bash
set
-euo
pipefail
# Diff two files with syntax highlighting using pygmentize.
# pygmentize should be a pygmentize wrapper with your preferred
# pygmentize settings (formatter / style / filters)
function
prepare
()
{
local
fn
=
$1
# Work around https://bitbucket.org/birkenfeld/pygments-main/issues/1437
if
[[
"
$fn
"
==
/dev/null
]]
then
return
fi
local
lexer
lexer
=
$(
pygmentize
-N
"
$fn
"
)
#printf "Detected lexer of %q as %q\n" "$fn" "$lexer" 1>&2
if
[[
"
$lexer
"
==
text
]]
then
expand
"
$fn
"
| pygmentize-term
-g
else
expand
"
$fn
"
| pygmentize-term
-l
"
$lexer
"
fi
}
# Use colordiff (instead of diff --color=always) solely because it
# produces consistent formatting on a per-line basis, saving us from
# having to keep track of state across lines
diff
=(
colordiff
--color
=
yes
)
for
arg
in
"
$@
"
do
if
[[
$arg
==
-
*
]]
then
diff+
=(
"
$arg
"
)
else
exec
{
fd
}
< <
(
prepare
"
$arg
"
)
diff+
=(
/dev/fd/
$fd
)
fi
done
sed
=(
sed
# replace "all attributes off" (used by Pygmentize to turn off
# bold) with "normal intensity"
-e
's/\x1b\[00m/\x1b[22m/g'
# Replace colordiff's foreground colors with some dark background
# colors. You can customize them here.
-e
's/^\x1b\[0;36m/\x1b[0;36;48;5;23m/'
# cyan
-e
's/^\x1b\[0;31m/\x1b[0;31;48;5;52m/'
# red
-e
's/^\x1b\[0;32m/\x1b[0;32;48;5;22m/'
# green
# Extend background color across the entire terminal window width
-e
's/\x1b\[0;0m$/\x1b\[K\x1b[0m/'
)
"
${
diff
[@]
}
"
|
"
${
sed
[@]
}
"
pygmentize-term
0 → 100755
View file @
76c4989e
#!/bin/sh
exec
pygmentize
-f
terminal256
-O
bg
=
dark,style
=
monokai
"
$@
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment