From 2a988d33c5e48a2e4a6d004df84628890bb41f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 27 Jul 2021 22:33:03 +0200 Subject: vipatch: Edit given file --- bin/vipatch | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'bin') 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 + +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; } -- cgit v1.2.3