DEV Community

David Cantrell
David Cantrell

Posted on

2

TIL: diff-so-fancy; and some funky git config

I just discovered diff-so-fancy, and very nice it is too. I immediately added it to my standard git config, which is semi-automatically installed on every machine I use. However, I've not (yet) installed diff-so-fancy on all the machines I use, and for those platforms for which it's not packaged I probably won't bother installing it from source.

But if I just follow the author's instructions which amount to adding this to my ~/.gitconfig:

[core]
    pager = "diff-so-fancy | less --tabs=4 -RFX"
Enter fullscreen mode Exit fullscreen mode

then git diff will break:

$ git diff HEAD^
diff-so-fancy | less --tabs=4 -RFX: diff-so-fancy: command not found
Enter fullscreen mode Exit fullscreen mode

but there's an easy fix! Whatever is in pager is just shell code, so this works:

[core]
    pager = "if [ ! -z \"$(which diff-so-fancy)\" ]; then diff-so-fancy | less --tabs=4 -RFX; else less; fi"
Enter fullscreen mode Exit fullscreen mode

The output from git diff is piped into that little script. If diff-so-fancy is installed (ie if "$(which diff-so-fancy)" is not zero-length) then it does exactly what diff-so-fancy's author suggests. Otherwise, if diff-so-fancy isn't installed, just run less.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (2)

Collapse
 
10xlearner profile image
10x learner •

Very nice tool ! Thank you @drhyde to allow me to discover such gem ! 😊

Image description

Collapse
 
karnerth profile image
Thomas Karner •

I personally prefer github.com/dandavison/delta

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay