Settings

Theme

Show HN: GitHub style split diffs in your terminal

github.com

178 points by milkbikis 5 years ago · 52 comments

Reader

kbd 5 years ago

I already use delta for this: https://github.com/dandavison/delta

I thought delta was fairly well-known by now so I was surprised to see this project not mention it (the readme already has a section for that). I wonder what they've chosen to do differently, besides write it in Node.js.

jez 5 years ago

When I find myself wanting a split diff in the terminal, I tend to gravitate towards just using Vim’s built in diff mode via vim-fugitive. I even have some git aliases that will open vim and and show fugitive diffs for every file changed on the current branch.

The I like this over fancy CLI diff viewers for a handful of reasons:

- It re-uses my editor config (no need to fuss with that tools ad hoc config format)

- I can navigate the diff with my editor’s navigation tools (expand or hide context lines, open/close/reorganize tabs, etc.)

- My editor’s language-aware tooling kicks in. I can jump to def, reveal types, and find all references while reading the diffs.

I wrote more about some of the specific workflows I use in this post, if you’re curious to level up from a CLI-only diff workflow:

https://blog.jez.io/cli-code-review/

There’s a time and a place for CLI-only diff viewers, and kudos to the author for building a tool they enjoy! I’ve just found that they fit into a sort of uncanny valley of simplicity and power for my needs.

  • i_am_not_elon 5 years ago

    You and I have similar setups! I love it, but there's one thorn that I've not been able to figure out yet.

    Have you (or anyone reading this) been able to figure out how to get diff-highlight to be more intelligent so that if 'foo' changes to "foo", the highlighter is smart enough to only highlight the quotes as changing, but not the word foo? (Though this example is trivial, any time you've got two changes on the same line, this issue occurs where everything in between those changes gets highlighted as well.) I noticed that other tools in this thread such as delta and banga don't suffer from this issue.

weitzj 5 years ago

I enjoy having good terminal ergonomics for Git.

What works for me is tig for git diffs.

Also very impressive is kitty-diff. If you use kitty as your OpenGL enabled terminal https://sw.kovidgoyal.net/kitty/kittens/diff.html

  • kbd 5 years ago

    I forgot kitty has kitty-diff! I love kitty as my terminal.

busterarm 5 years ago

You can just use icdiff to get handsome-looking split diffs in terminal. https://github.com/jeffkaufman/icdiff

in your .gitconfig

    [diff]
    tool = icdiff

    [difftool]
    prompt = false

    [difftool "icdiff"]
    cmd = /usr/bin/icdiff --line-numbers $LOCAL $REMOTE | less -eFXR
then git difftool
seabass 5 years ago

This is cool! A bit slow to start up, probably due to starting up a node process each run, but looks great. Wondering if you have a theme that doesn't include a background color as I quite like my terminal's defaults.

nfoz 5 years ago

I just use `vimdiff`, but this looks better.

  • Brian_K_White 5 years ago

    Same. I mean... vim, right there already for free, and the invocation is rather ridiculously simpler.

    And vimdiff is even an editor not just a viewer.

    Now if it was say, Meld in a terminal, that would be worth talking about and I installing some stack as a dependency.

  • gnufx 5 years ago

    Bad luck! Emacs Ediff worked well for me before Git, and it still does (frequently in a tty, and preferably not with Git).

zeckalpha 5 years ago

`diff -y` works in a pinch but I generally use icdiff: https://www.jefftk.com/icdiff

bovine3dom 5 years ago

Related but for single pane diffs: https://github.com/so-fancy/diff-so-fancy

vendiddy 5 years ago

The diffs look beautiful. One suggestion to the author be to bundle this as a self-contained binary. This would have a huge impact on whether I want to install it.

For this, I would look into Deno, which supports self contained binaries with typescript. I've never tried it myself so not sure how much work this would be.

  • milkbikisOP 5 years ago

    Yeah I looked into bundling and deno, but neither of those seemed palatable at this point. Deno’s ecosystem is still quite small, so I’d have to implement things like syntax highlighting from scratch which is not feasible. Other bundling options don’t seem all that reliable / popular and they aren’t really solving the actual issue of untrusted dependencies. So my current take is to just use node and be very conservative with dependencies.

nyellin 5 years ago

Is anyone familiar with a good way to programatically create a diff like this as an image?

I wrote a small script that tracks changes to your kubernetes cluster and sends a diff of the yaml to Slack. It works but I want to prettify the diff with a GitHub style diff and I need it in image format to send to slack.

  • milkbikisOP 5 years ago

    I actually tried to automate the screenshots for this project's readme using GitHub actions, but struggled to get it to produce the same quality screenshots as my local machine. This is the script I use for now, which has to be invoked manually: https://github.com/banga/git-split-diffs/blob/main/scripts/g...

    • nyellin 5 years ago

      Thank you. If you find a better way which works on a headless Linux container let me know. I would be interested in the older versions of your automation even if the output is worse quality so long as the quality is acceptable.

nishparadox 5 years ago

I've been using delta: https://github.com/dandavison/delta

It can be easily set up...

gigatexal 5 years ago

I’ve been looking for just this!!! Thank you!!

manannayak 5 years ago

Nice work, banga!

nickstinemates 5 years ago

Looks beautiful

baby 5 years ago

This is amazing!

shaicoleman 5 years ago

Awesome, thanks!

dikaio 5 years ago

Nice work!

AveryEm 5 years ago

> 99.1% TypeScript disappointment

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection