alias diff='diff --color=auto'

# Not to be confused with `splitdiff` from `patchutils`.
# Splits the hunks of a diff into separate files with names based on the first
# argument, making sure the file header is present in each one.
diffsplit()
(
  prefix="$1"; shift
  awk -v prefix="$prefix" '
    /^diff/ { H = 1; h = $0; next; }
    /^@@/   { H = 0; print h > (f = sprintf("%s%04d.patch", prefix, ++F)); }
    H       { h = h "\n" $0;  }
    !H      { print $0 >> f; }
  ' "$@"
)