]> Sergey Matveev's repositories - schwabrak.git/blob - comment
Explicit empty line separator
[schwabrak.git] / comment
1 #!/usr/bin/env zsh
2
3 root=$0:h:a
4 . $root/lib.zsh.rc
5
6 usage() {
7     die Usage: $0 ISSUE
8 }
9
10 [[ -n $1 ]] || usage
11 issue=${1#issues/}
12 comment=issues/$issue/comment
13
14 local tmp=`mktemp`
15 trap "rm -f $tmp" HUP PIPE INT QUIT TERM EXIT
16 { $PERL -npe 's/^/# /' < $comment ; print } > $tmp
17 zmodload -F zsh/stat b:zstat
18 zstat -A ctimePrev +ctime $tmp
19 $EDITOR $tmp
20 zstat -A ctime +ctime $tmp
21 [[ $ctime != $ctimePrev ]] || {
22     echo Aborting comment >&2
23     exit 0
24 }
25 if [[ -s $comment ]]; then
26     $PERL -ne 'print if $can; if (/^$/) { $can=1 };' < $tmp > $comment
27 else
28     cat < $tmp > $comment
29 fi
30 git add $comment