document updated 12 years ago, on Mar 23, 2012
What ways are there to generate an ANSI colorized diff? (sometimes 'vimdiff' isn't available on all machines)
- vimdiff
- colordiff -C 999999 file1 file2
- Text::WordDiff::ANSIColor
- command-line one-liner
function cdiff { diff -U 999999 "$@" | perl -pe 's/^(\+.*)/\e[92m$1\e[0m/g; s/^(-.*)/\e[91m$1\e[0m/g'; }
cdiff file1 file2
- similarly, with git diff, you can:
function gitdiff { git diff --unified=99999 "$@" | perl -pe 's/^\+(.*)/+\e[92m$1\e[0m/g; s/^-(.*)/-\e[91m$1\e[0m/g' | less -R -p '^[^ ]'; }