Browse code

Add diffsplit

Robert Cranston authored on 29/04/2026 15:19:25
Showing 1 changed files

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