~charles/dotfiles

ref: 42ae9b59869483135b3070a0f00deb773c85adb0 dotfiles/overlay.full/bin/new-reference -rwxr-xr-x 492 bytes
42ae9b59Charles Daniels add new-reference 3 months ago
                                                                                
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
#!/bin/sh

set -e
set -u

# create a new "reference" zettlekasten from a URL

# We do this up front in case it fails, that way we don't create spurious
# zettles.
BIB="$(url2bib "$1" | bib2yaml)"

ZETTLE="$(zettle new)"

function finish() {
	rm -f "$ZETTLE.tmp"
}
trap finish EXIT


awk '$1 == "---" {n++} (n < 2) {print($0)}' < "$ZETTLE" > "$ZETTLE.tmp"
printf '%s\n' "$BIB" >> "$ZETTLE.tmp"
printf 'tags:\n  - reference\n---\n\n' >> "$ZETTLE.tmp"
mv "$ZETTLE.tmp" "$ZETTLE"

echo "$ZETTLE"