aboutsummaryrefslogtreecommitdiff
path: root/bin/vipatch
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-27 22:33:03 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-27 22:33:03 +0200
commit2a988d33c5e48a2e4a6d004df84628890bb41f29 (patch)
tree0760247ca8f38017a9eb0bb80501f993c95d9a4c /bin/vipatch
parenta6926740758524f2c10db70b851d8fc6809e9242 (diff)
downloadpatches-2a988d33c5e48a2e4a6d004df84628890bb41f29.tar.gz
vipatch: Edit given file
Diffstat (limited to 'bin/vipatch')
-rwxr-xr-xbin/vipatch14
1 files changed, 11 insertions, 3 deletions
diff --git a/bin/vipatch b/bin/vipatch
index d860f93..ecb45c9 100755
--- a/bin/vipatch
+++ b/bin/vipatch
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -f
# vipatch -- edit unified diff
@@ -6,7 +6,15 @@
# a patch generated by diff -u, depending on the actual
# number of added/removed lines.
-ep | awk -vname=${0##*/} '
+IFS=''
+
+tmp=$(mktemp /tmp/vipatch.XXXXXX)
+trap 'rm $tmp; trap -' INT QUIT EXIT
+
+cat $1 > $tmp
+${EDITOR:-vi} $tmp </dev/tty >/dev/tty
+
+cat $tmp | awk -vname=${0##*/} '
/^@@ / { if (head) printpatch(); head = $0 "\n"; next }
head && /^---/ { print; next }
head && /^\+\+\+/ { print; next }
@@ -47,4 +55,4 @@ function printpatch() {
function abs(n) {
return (n > 0) ? n : -n;
}
-'
+' | { [ -z "$1" ] && cat || cat > $1; }