#!/usr/bin/env zsh root=$0:h:a . $root/lib.zsh.rc usage() { die Usage: $0 ISSUE } [[ -n $1 ]] || usage issue=${1#issues/} comment=issues/$issue/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 $tmp $EDITOR $tmp zstat -A ctime +ctime $tmp [[ $ctime != $ctimePrev ]] || { echo Aborting comment >&2 exit 0 } if [[ -s $comment ]]; then $PERL -ne 'print if $can; if (/^$/) { $can=1 };' <$tmp >$comment else cat <$tmp >$comment fi git add $comment