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 ; print } >$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
+ print Aborting comment >&2
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