]> Sergey Matveev's repositories - schwabrak.git/commitdiff
Workability with empty comment
authorSergey Matveev <stargrave@stargrave.org>
Tue, 26 Mar 2024 14:29:59 +0000 (17:29 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 26 Mar 2024 14:29:59 +0000 (17:29 +0300)
comment

diff --git a/comment b/comment
index a2fc9e4193cd891d6e79d5e9b13cdbf589516d6fd1805b401cca25c58d3ccf79..f4784bd1111fcdf084a0c454b792c15ca168f6727ced26c848d2d14a1dc079ff 100755 (executable)
--- a/comment
+++ b/comment
@@ -11,15 +11,20 @@ usage() {
 issue=${1#issues/}
 comment=issues/$issue/comment
 
-$PERL -i -npe 's/^/# /' $comment
+local tmp=`mktemp`
+trap "rm -f $tmp" HUP PIPE INT QUIT TERM EXIT
+$PERL -npe 's/^/# /' < $comment > $tmp
 zmodload -F zsh/stat b:zstat
-zstat -A ctimePrev +ctime $comment
-$EDITOR $comment
-zstat -A ctime +ctime $comment
+zstat -A ctimePrev +ctime $tmp
+$EDITOR $tmp
+zstat -A ctime +ctime $tmp
 [[ $ctime != $ctimePrev ]] || {
     echo Aborting comment >&2
-    $PERL -i -npe 's/^# //' $comment
     exit 0
 }
-$PERL -i -ne 'print if $can; if (/^$/) { $can=1 };' $comment
+if [[ -s $comment ]]; then
+    $PERL -ne 'print if $can; if (/^$/) { $can=1 };' < $tmp > $comment
+else
+    cat < $tmp > $comment
+fi
 git add $comment