aboutsummaryrefslogtreecommitdiff
path: root/conv
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-09 22:52:03 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-09 22:52:16 +0200
commite67c4cfb5fac5b75fcde34d379cad09bf28813aa (patch)
treefbebdd122f7aab520eef01a2253760ae202c20b2 /conv
parent13329639344009a67a4f45759f1106182c2925e3 (diff)
downloadpatches-e67c4cfb5fac5b75fcde34d379cad09bf28813aa.tar.gz
conv: Add -i flag (interactive mode)
Diffstat (limited to 'conv')
-rwxr-xr-xconv64
1 files changed, 56 insertions, 8 deletions
diff --git a/conv b/conv
index 7d5a508..ded047a 100755
--- a/conv
+++ b/conv
@@ -5,13 +5,28 @@
IFS='
'
-echo '$NetBSD'
-echo
-sed '
- /^diff/d;
- /^index/d;
- s/^--- .*/&/;
-' |
+{
+ echo '$NetBSD'
+ echo
+
+ # get patch description
+ if [ x"$1" = x"-i" ]; then
+ f=`mktemp`
+ echo 'Edit patch description...' > $f
+ </dev/tty >/dev/tty vi $f
+ c=`cat $f`
+ if [ x"$c" != x"Edit patch description..." ]; then
+ printf '%s\n\n' "$c"
+ fi
+ rm $f
+ fi
+
+ sed '
+ /^diff/d;
+ /^index/d;
+ s/^--- .*/&/;
+ '
+} |
while read line; do
case "$line" in
diff*) ;;
@@ -25,4 +40,37 @@ while read line; do
*)
echo "$line" ;;
esac
-done
+done | {
+if [ x"$1" = x"-i" ]; then
+ # read patch before proceeding
+ patch=`cat`
+
+ # get patch directory
+ dir=$2
+ if [ -z "$2" ]; then
+ echo -n 'Package name: ' >/dev/tty
+ read dir </dev/tty
+ fi
+ dir=~/patches/$dir
+ mkdir -p $dir
+
+ # get patch name
+ name=$3
+ if [ -z "$3" ]; then
+ echo -n 'Patch name: ' >/dev/tty
+ read name </dev/tty
+ fi
+
+ # write patch if it doesn't already exist
+ if [ -e $dir/$name ]; then
+ f=`mktemp`
+ echo error: $dir/$name already exists; saving to $f 1>&2
+ exit 1
+ else
+ printf '%s\n' "$patch" > $dir/$name
+ echo $dir/name 1>&2
+ fi
+else
+ cat
+fi
+}