
Show HN: A syntax highlighter for Git and diff output, written in Rust - Myrmornis
https://github.com/dandavison/delta
======
apas
This is neat. In a similar fashion I'm a big fan of diff-highlight, [0] which
post-processes the git diff and highlights with color the differing segments.
It's super lightweight and part of the official git repo; I've saved it as a
standalone #!/bin/perl in my $PATH and then included it in my .gitconfig:

    
    
      [pager]
       log = /Users/user/.bin/diff-highlight | less
       show = /Users/user/.bin/diff-highlight | less
       diff = /Users/user/.bin/diff-highlight | less
    

[0]: [https://github.com/git/git/tree/master/contrib/diff-
highligh...](https://github.com/git/git/tree/master/contrib/diff-highlight)

~~~
mookid11
Sort of related: as I never made diff-highlight work correctly on Windows, I
wrote diffr[0] which goes a little bit behond what diff-highlight does.

[0]: [https://github.com/mookid/diffr](https://github.com/mookid/diffr)

------
Myrmornis
Delta[0] applies syntax highlighting to the code sections of git and diff
output, and uses background colors (instead of +/-) to indicate added /
removed content. It's written in Rust, and uses the syntect[1] highlighting
library. That's the same library that bat[2] uses, so delta supports all the
same color themes, and any bat configuration that you already have in place
(environment variables, custom themes/language support) is automatically
honored by delta. Delta also infers and highlights substrings that differ
between lines (similar to Github, Gitlab and other diff viewers) and
optionally cleans up the raw diff output slightly to make it more human
readable.

[0] [https://github.com/dandavison/delta](https://github.com/dandavison/delta)

[1] [https://github.com/trishume/syntect](https://github.com/trishume/syntect)

[2] [http://github.com/sharkdp/bat/](http://github.com/sharkdp/bat/)

------
frou_dh
Does it work properly with `git add -p`? That's a longstanding issue of diff-
so-fancy: [https://github.com/so-fancy/diff-so-
fancy/issues/35](https://github.com/so-fancy/diff-so-fancy/issues/35)

~~~
Myrmornis
Yes it does. Thanks for asking, I hadn't tested this out. The key is the
`--color-only` argument, which guarantees that, other than ANSI color escape
sequences, the original output from git is unchanged:

    
    
      [interactive]
          diffFilter = delta --color-only

------
lzybkr
If you to use this on Windows, you'll need to update `less.exe` with my
patched version -
[https://github.com/lzybkr/less/releases/tag/fix_windows_vt](https://github.com/lzybkr/less/releases/tag/fix_windows_vt)

------
bdefore
As a suggestion, I'd have the configuration step in 'Configure git to use
delta' not reference a theme that doesn't come with the initial install as
you've done with 'base-16.ocean.dark'. I had to investigate why, and
(admittedly happily) then found out about bat and installed that and changed
it to 'zenburn'. But I suppose most users would like to see it work without
having to do that.

~~~
Myrmornis
Thank you! Fixed that.

~~~
bdefore
I don't know if this is better per-se but my diff-so-fancy config sat in
[pager] rather than [core]. I verified that git-delta works as configured this
way instead:

    
    
      [pager]
              diff = delta --dark --plus-color="#012800" --minus- color="#340001" --theme="zenburn"

------
kccqzy
This might be just me but looking at the screenshots, I clearly prefer the
GitHub one as it shows the line numbers of every line in both before and
after. Line numbers make jumping between the diff and the editor fast and
efficient.

~~~
Myrmornis
Thanks, that's definitely a feature that could be added. My original thought
was that the line numbers in the _after_ file are nearly always what one
wants, since that's the version that your editor will most naturally be
displaying. And I wanted to reduce visual clutter. Delta currently displays
just the first line number of each diff hunk; not on every line. But that's
also something that could be made configurable.

EDIT: In fact an issue was opened for this very recently:
[https://github.com/dandavison/delta/issues/130](https://github.com/dandavison/delta/issues/130)

Ideally, I think that a mouse click in an appropriate location in a terminal
emulator window should open the user's editor on the correct line of the
correct file.

------
nitsky
Just installed it, it looks great and is a big step up from diff-so-fancy.
Thanks for making this!

------
willbw
Anyone else getting this issue?

    
    
      ⟩ git diff
      error: Found argument 'Extended' which wasn't expected, or isn't valid in this context
    
      USAGE:
          delta --dark --minus-color <minus_color> --plus-color <plus_color> --theme <theme>
    
      For more information try --help
    
    

My ~/.gitconfig file has the copy pasted lines from the github example

    
    
      [core]
          pager = delta --dark --plus-color="#012800" --minus-color="#340001" --theme="Monokai Extended"
    
      [interactive]
          diffFilter = delta --color-only
    

Installed with homebrew on macos.

~~~
Myrmornis
Thanks! I made a hasty edit to the README earlier. Try

    
    
      --theme='Monokai Extended'
    

It seems that in ~/.gitconfig, a theme name with spaces must be quoted with
single quotes. At least, that is working on MacOS.

------
j88439h84
Can anybody suggest a --plus-color that looks nice on a solarized-dark blue
terminal?

~~~
squaresmile
I settled on --plus-color="#157330" \--minus-color="#731525".

------
atombender
This is fantastic. Kudos!

A tip for people who (like me) don't like that Git pages by default: With
Delta, you can disable this it by adding this to your environment:

    
    
      export BAT_PAGER=cat

------
yboris
Seems related: _diff2html_

[https://diff2html.xyz/](https://diff2html.xyz/)

npm-installed cli which shows you git diff in your browser

------
axegon_
Stuff like that makes my daily code reviews so so SO much better! I can't
thank you enough!

~~~
Myrmornis
This is good to hear :)

------
firloop
Anyone know how to get this working with vim-fugitive?
[https://github.com/tpope/vim-fugitive](https://github.com/tpope/vim-fugitive)

~~~
airblade
Not sure about vim-fugitive, but vim-gitgutter's hunk previews have intra-line
highlighting. I mention it because people often use the two plugins together
(and I'm pleased with how vgg's highlighting turned out :)

[https://github.com/airblade/vim-gitgutter](https://github.com/airblade/vim-
gitgutter)

------
Klasiaster
A comparison to [http://www.colordiff.org/](http://www.colordiff.org/) would
be good in the table of the README.

------
xixixao
FYI that dark theme example has unreadable blue for me in looking at it with
night shift on. I'd suggest swapping out for a better theme.

~~~
Myrmornis
I agree. If anyone has nice combinations of delta background colors and syntax
highlighting theme for dark backgrounds, please send them my way! (Here, or
PR/issue).

------
ninjaranter
Is there a way to see diff output side-by-side? I personally find that much
easier to parse through with a widescreen monitor.

~~~
Myrmornis
Hi, thanks, this is an interesting question and there have been requests for
it. Two possibilities come to mind:

1\. Delta constructs the side-by-side diff itself (a parsed internal
representation of it), and then colorizes it.

2\. Delta gains the ability to parse side-by-side diffs being emitted by
another tool.

My currently feeling is that (1) is more attractive / easier.

~~~
jwatt
#1 would be useful for sure.

------
loevborg
The light theme looks beautiful, thanks!

~~~
Myrmornis
Thanks. I like the light theme also. If anyone has suggestions of good {theme,
background-highlight-colors} choices, especially for dark backgrounds, please
open a PR/issue and we can add them to the README.

------
j88439h84
I can't tell if --dark is changing anything. That seems to be the default on
my dark terminal?

~~~
Myrmornis
Yes, --dark is the default and it will choose a dark theme. To see a demo of
other dark themes, you can do

    
    
      delta --list-themes --dark
    

and then delta --theme <chosen theme> to select it.

------
eximius
icdiff is my current favorite.

This does look nice, though I'm a little confused by the choice to highlight
the section below the function declaration change even though it doesnt appear
to have a change.

~~~
Myrmornis
Is it the hunk header you're referring to? That's something that git outputs,
like this, before the diff hunk:

    
    
      @@ -62,17 +62,17 @@ class MyClass:
    

Delta makes that more prominent by surrounding it with a box (by default) and
getting rid of the for-machines characters that git puts there. It doesn't
apply background colors to it though: delta only applies background red and
green shading to removed/added lines.

(I believe that one can customize the regular expressions that git uses to
decide on the hunk header; they're sometimes appropriate and sometimes not,
for the languages that I use.)

------
highmastdon
I think there’s ‘tig’ as well. You can use it as ‘git diff | tig’

------
fallingmeat
can we get one written in Ada too?

