summaryrefslogtreecommitdiff
path: root/scripts/journal-note
blob: f91a07ba8c330a8f1b163fd8eb2253ccc85fef34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh

set -e

if [ "$#" != 1 ]
then
    echo "Usage: $0 title"
    exit 1
fi

title="$1"
temp="$(mktemp --tmpdir=$HOME/Journal)"

cat << eof > "$temp"
[[!meta title="$title"]]
[[!tag ]]
[[!meta date="$(date +%Y-%m-%dT%H:%M)"]]

eof

checksum="$(mktemp)"
md5sum "$temp" > "$checksum"
vi "$temp"
if md5sum --status -c "$checksum"
then
    echo "No change to note, aborting."
    rm "$temp" "$checksum"
    exit 1
fi

cat << eof >> "$temp"

[[!meta done="$(date +%Y-%m-%dT%H:%M)"]]
eof

cd "$HOME/Journal/src"
filename="notes/$(date +%Y-%m-%d-%H:%M.mdwn)"
if [ -e "$filename" ]
then
    filename="notes/$(date +%Y-%m-%d-%H:%M:%S.mdwn)"
fi
cp "$temp" "$filename"
bzr add "$filename"
bzr commit -m "New note" "$filename"
ikiwiki --setup ../ikiwiki.setup --refresh
rm "$temp" "$checksum"