The new --diff feature looks very cool.
I could not figure out how to use it with two files. Is there a way yet? Or a workaround?
bat --diff a.txt b.txt does not work.
Unfortunately, the --diff feature is only intended to filter out lines that haven't been changed since the last time the file was committed to the git index.
-d, --diff Only show lines that have been added/removed/modified with respect to the Git index. Use --diff-context=N to control how much context you want to see.
If you're looking to highlight a diff between two files, you might want to consider using delta (diff -u a.txt b.txt | delta), or diff a.txt b.txt | bat -ldiff.
You could technically work around it by creating a new git repository and artificially creating a difference between the index and the workspace, but it's not pretty and has some noticeable overhead:
#!/usr/bin/env bash
TEMP="$(mktemp -d)"
FILENAME="$(basename "$1")"
(cd "$TEMP" && git init -q)
cp "$1" "$TEMP/$FILENAME"
(cd "$TEMP" && git add "$FILENAME" && git commit -q -m "Temporary")
cp "$2" "$TEMP/$FILENAME"
(cd "$TEMP" && bat --diff "$FILENAME")
rm -rf "$TEMP"
Which you would then call with ./script.sh a.txt b.txt.
Overhead:
$ time ./script.sh a.txt b.txt
Executed in 306.34 millis fish external
usr time 98.97 millis 172.00 micros 98.80 millis
sys time 55.54 millis 527.00 micros 55.01 millis
$ time diff -u test.sh test.sass | delta --paging=never
Executed in 74.56 millis fish external
usr time 66.00 millis 230.00 micros 65.77 millis
sys time 8.03 millis 802.00 micros 7.22 millis
Okay, so there is no solution now.
I use diff-so-fancy at the moment. But it seems that bat can't replace that at the moment
Thanks a lot! :)
Most helpful comment
Unfortunately, the
--difffeature is only intended to filter out lines that haven't been changed since the last time the file was committed to the git index.If you're looking to highlight a diff between two files, you might want to consider using delta (
diff -u a.txt b.txt | delta), ordiff a.txt b.txt | bat -ldiff.