#!/bin/bash

# stolen from quilt.... hence GPL v2

# example usage
#   diff -u blah1 blah2 | colordiff | less -R
#   git diff | colordiff | less -R
#
# code taken from quilt... love the GPL

setup_colors()
{
	local C=diff_hdr=32:diff_add=36:diff_mod=35:diff_rem=35:diff_hunk=33:diff_ctx=35:diff_cctx=33:patch_offs=33:patch_fuzz=35:patch_fail=31:patch_applied=32:clear=00
	C=${C//=/=\'$'\e'[}
	C=color_${C//:/m\'; color_}m\'
	eval $C
}
	
colorize() {
    sed -e '
	s/^\(Index:\|---\|+++\|\*\*\*\) .*/'$color_diff_hdr'&'$color_clear'/
	t ; s/^+.*/'$color_diff_add'&'$color_clear'/
	t ; s/^-.*/'$color_diff_rem'&'$color_clear'/
	t ; s/^!.*/'$color_diff_mod'&'$color_clear'/
	t ; s/^\(@@ \-[0-9]\+\(,[0-9]\+\)\? +[0-9]\+\(,[0-9]\+\)\? @@\)\([ \t]*\)\(.*\)/'$color_diff_hunk'\1'$color_clear'\4'$color_diff_ctx'\5'$color_clear'/
	t ; s/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*.*/'$color_diff_cctx'&'$color_clear'/
	'
}

setup_colors

colorize
