-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotate
executable file
·48 lines (39 loc) · 919 Bytes
/
notate
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
47
48
#!/bin/bash
# Author: Conner McDaniel
# https://github.com/connermcd/bin
# MIT license
set -e
pdf="$1"
doi="$(pdf2doi ${1})"
bib=$(curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex")
title=$(echo "$bib" | sed -n '1p' | cut -d{ -f2 | sed 's/,//')
file_name=
make_file() {
new_pdf="$(dirname $pdf)/$1.pdf"
[[ ! -f "$new_pdf" ]] && mv "$pdf" "$new_pdf"
bib=$(echo "$bib" | sed "1a\\\tpdf = {$new_pdf},")
cat >"$file_name" <<EOF
~~~.bib
$bib
~~~
# Summary
# Quotes and Data
# Questions
EOF
}
check_file() {
file="$HOME/Documents/Notes/Papers/$1.md"
if [[ -f $file ]]; then
file_doi=$(grep -o -E "doi = {[^}]*" $file | cut -d{ -f2)
if [[ "${file_doi,,}" =~ "${doi,,}" ]]; then
file_name="$file"
else
check_file "${1}+"
fi
else
file_name="$file"
make_file "$1"
fi
}
check_file "$title"
vim "$file_name"