Skip to content

Instantly share code, notes, and snippets.

@doitian
Last active May 26, 2018 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doitian/4046a5d53233d8351c1bb981ae2d3b1d to your computer and use it in GitHub Desktop.
Save doitian/4046a5d53233d8351c1bb981ae2d3b1d to your computer and use it in GitHub Desktop.
Convert `git diff` output to the format can be recognized by vim quickfix.
#!/usr/bin/env bash
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 "";
}
'
@doitian
Copy link
Author

doitian commented May 26, 2018

Example usage in vim:

command! -nargs=* Diff2qf :cexpr system("diff2qf", system("git diff -U0 " . <q-args>))

Then

:Diff2qf
:Diff2qf -a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment