Delta: A syntax-highlighting pager for Git, diff, grep, and blame output
github.com
github.com
As someone else already mentioned there is also bat[1], which was also set and forget, I aliased cat to bat and have a seperate alias vcat for 'vanilla cat' /usr/bin/cat
(In bash at least. Not sure about newfangled shells!)
They should not be coloring the grammar, we are good at picking out grammar, they should be highlighting the symbols. each different variable and function name should be getting it's own color. that is, the goal is to make it quicker to distinguish different symbols, not that they are a symbol.
But this is much harder than stylizing the grammar so all our tooling sticks with the easy thing rather that the useful thing. Now, I am being a bit mean on grammar styling. It does help quite a bit but I would like to see a symbol matching engine in action to see if that really works.
Unfortunately I don't remember where I read the original post and am unable to attribute it correctly.
update: while trying to look it up I found this https://www.wilfred.me.uk/blog/2014/09/27/the-definitive-gui...
I'm not convinced of the argument, but still a bit curious.
I sometimes highlight a variable to follow it and make sure I don't miss an instance of it, so that I totally get. But not sure we have enough colors and contrast to make sense to follow many variables without cluttering everything up. A compromise might be to manually color up to 3 or something variables.
... but the cases where that helps may be a sign that the code isn't very readable to begin with (helping with messy codebases is a proper usecase though!).
git diff --color-words --word-diff-regex='\w+|.'git config --global diff.colorWords true
git config --global diff.wordRegex '\w+|.'
It's literally in the PR you mention:
syntax-highlighting very long lines (e.g. minified .js) will be very slow if they are not truncated
--- a/some/path/to/file.c
+++ b/some/path/to/file.c
I often cmd-click in iTerm to open a file in an editor, but this doesn't work here because of the a/ and b/ prefixes. Any way to make Git format the file name better? I don't even need two lines here. git config --global diff.noprefix true
Checkout the manual for more prefix options.Delta looks clean, and is super fast
function delta_sidebyside {
if [[ COLUMNS -ge 120 ]]; then
DELTA_FEATURES='side-by-side'
else
DELTA_FEATURES=''
fi
}
trap delta_sidebyside WINCH $ TEST=3
$ if [[ TEST -gt 2 ]]; then echo "honk"; fi
honk
$ TEST=1
$ if [[ TEST -gt 2 ]]; then echo "honk"; fi
$
That lets you do things like $ if [[ TEST*3 -gt 6 ]]; ...
without having to nest even more double parentheses.You're correct about having to export DELTA_FEATURES at least once. (I export it outside of the function, but no harm in doing so whenever it's set -- but it's not required to re-export it when you change the value.) Thanks for catching that!
If you use the terminal at all, get them!
That would be one of the coolest news in weeks!
For difftastic, there is difftastic package in MELPA, see also https://github.com/pkryger/difftastic.el for instructions.
`env GIT_EXTERNAL_DIFF=difft git log -p --ext-diff`
Hope it helps :)
difft = -c diff.external=difft diff
I may add a similar alias for delta
As a bit of feedback, you might wish to put a section showing how to make a git alias for diffr, to complement the section on how to install it as the default. I know how to do this already, because I use delta and dft depending on what I need to see, but it would be useful to others to have a copy-paste solution handy.
#!/usr/bin/fish
gsettings set org.gnome.desktop.interface gtk-theme "Adwaita-dark"
fish_config theme choose "ayu Mirage"
yes | fish_config theme save
echo "--theme=OneHalfDark" > ~/.config/bat/config
kitten themes --reload-in=all "Ayu Mirage"
The bat config change will make delta respect my "system" theme. 

To automatically display the light or dark version of images depending on their gh theme (works html style too)I'm also fond of
<p align="center">
....
</p>
Which I notice you do :), but did you know you could also do it to tables and center the caption? <table align="center">
<tr>
<td>
<img width=800px src="https://user-images.githubusercontent.com/52205/87230973-412eb900-c381-11ea-8aec-cc200290bd1b.png" alt="image" />
<br>
<p align="center"><sub>delta with <code>side-by-side</code> and <code>line-numbers</code> activated</sub></p>
</td>
</tr>
</table>
This isn't really a critique or anything, it is that I appreciate that you took the time to make things look pretty and it seems like you'd be interested in this kind of stuffAlso to others, this even works in issues and elsewhere. I find this stuff really helpful when writing issues
> To automatically display the light or dark version of images depending on their gh theme
Ah, good call. That could be a nice improvement -- creating light and dark versions of the screenshots with switching as you describe.
I find it easier to navigate that way since the diff of each file is in its own tab (yes I know... not how tabs are meant to be used)
For grep, vim's built in location list seems good enough. As for blame, I haven't used it since learning about git log -L. Vastly superior in my opinion.
We have non technical people looking at markdown PRs and commits in github and the diff viewer is terrible. It will highlight and entire paragraph because someone removed a trailing space. I use git-so-fancy locally which makes it much easier to see changes but I can't expect non-technical editors to move from their GitHub based workflow to a terminal based one
Any user feedback on how it is (perf etc) ?
https://raw.githubusercontent.com/dandavison/delta/main/them...
The related? project "bat" also looks interesting.
- rg (ripgrep): A grep replacement
- sk (skim): A grep/fzf/fzy replacement
- fd: A find replacement that's .gitignore+.ignore aware.
- eza: A replacement for ls that's git aware
- broot: A TUI file finder to browse large directories
- yazi: A file manager (I haven't used this one too much)
sk+rg + gawk in action to find files matching some text,
sk \
--ansi \
--interactive \
--cmd 'rg --color=always --line-number "{}"' --preview 'bat --color=always $(echo {} | gawk -F: "{print \$1}") --highlight-line $(echo {} | gawk -F: "{print \$2}")' \
| gawk \
-F: \
'{print $1}'I also use foot+fzy as a tiny sway dmenu replacement.. I started to make other kinds of custom tiny TUI popup menus using this strategy and it's great, since it all uses my terminal style and each is an extremely tiny 1 or 2 line script.
tbh I prefer to use less for previewing files anyway.
I've been using eza (and exa before it) for a long time, but only for the pretty and colored output. I didn't even know about the git support! I now added the --git flag to my alias and will try it out. Thank you!
curl … | prettier --parser html | bat
to get not-ugly HTML output from curl.
If Delta doesn't work like you expected and you want a standard diff output temporarily, no problem, you can run Git with
git -c core.pager=less
Note also that if you redirect the Git output, Git is smart enough to not call the pager (in this case, Delta)
This is a case of personal taste. My only complaint about Delta is its name. Delta is already a concept in Git, and every time that I need to search about it is a pain... I search directly by "dandavision delta"
I normally use vimdiff and lazygit to see diffs. No syntax coloring.
On a separate tangent - I haven't needed to do a gnarly merge in years it seems like. I feel like the dev community has collectively gotten better at git/SCM in general. Maybe I was super junior before but it's just not a problem I seem to face in daily software dev anymore.
Default git diff output is soooooooooo bad. This tool makes it closer to a good GUI tool. At which point why not just use one of the tools that is excellent and existed for decades?
Most of the time, diffs are small, and the overhead/break in workflow, of starting a separate GUI program just for them, can be big.
I can't fathom git diff in the terminal providing me value... ever? It's such a crappy and limited tool. My brain never learned to parse the +/- lines. I want a side-by-side view.
Which the linked tool does side-by-side. But I don't really run a diff unless it's for something non-trivial. In which case terminal still kinda sucks.
I don't see popping into a GUI as a loss. It's fast and snappy. No loss.
There's a class of programmers that seemingly live almost their entire life in the terminal. I've never been part of that class. My career has always been spent in a an IDE like Visual Studio, VSCode, or these days 10x. And that's assuming I'm not in something like Unity or Unreal. The terminal is something I regularly alt-tab to. It's never somewhere I stay.
Perhaps the answer is “git-delta attempts to provide a GUI like experience. If you can use a GUI you should. But if for some reason you can’t consider this as a less good alternative”.