I have set up diff-highlight as pager / highlighter for git.

    log = diff-highlight | less
    show = diff-highlight | less
    diff = diff-highlight | less

That works perfectly.

But how can I use diff-highlight for normal diff ?


You can define a function:

diff() { /usr/bin/diff "$@" | diff-highlight }

diff-highlight processes unified diffs (diff -u) but piping other formats appears to work — it passes them through unchanged.

To approximate the behaviour you get with git diff, you’d need colordiff too:

diff() { colordiff -u "$@" | diff-highlight | less -FRX }
  • thanks, but that does not work as it is. If I add '-u' to diff, then it works in monochrome. I had to change '/usr/bin/diff' to '/usr/bin/colordiff' to get what I want. I am not sure why your example works for you, but not for me. – Martin Vegter Feb 6 at 8:53
  • You asked how to use diff-highlight with normal diff ;-). Could you expand your question to make it explicit what you’re looking for? Is it something like “I want to run diff fileA fileB and see output similar to what I get with git diff fileA after configuring git with diff-highlight, including colours and paging”? – Stephen Kitt Feb 6 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.