#!/usr/bin/env bash
# :Diff2qf
# command! -nargs=* Diff2qf :cexpr system("diff2qf", system("git diff -U0 " . <q-args>))

awk '
  /^\+\+\+ b\// {
    chunk = -1;
    if (file != "") {
      print "";
    }

    file = substr($2, 3, length($2) - 2);
    next;
  }

  /^@@ / {
    if (chunk >= 0) {
      print "";
    }
    chunk = 3;

    gsub(/\+|,.*$/, "", $3);
    printf("%s:%s:", file, $3);

    next;
  }

  chunk > 0 {
    if (/^[-+]/) {
      printf("\t%s", substr($0, 2));
      chunk -= 1;
    }
  }

  END {
    print "";
  }
'
