-
Notifications
You must be signed in to change notification settings - Fork 0
/
reftj
executable file
·51 lines (39 loc) · 1.16 KB
/
reftj
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
49
50
#!/bin/bash
[ -z "$1" ] && echo "Give either a pdf file or a DOI as an argument." && exit
if [ -f "$1" ]; then
# Try to get DOI from pdfinfo or pdftotext output.
# doi=$(pdfinfo "$1" | grep -io "10\..*") ||
doi=$(pdftotext "$1" 2>/dev/null - | grep -io "10\..*" -m 1) ||
exit 1
else
doi="$1"
fi
# Default location
location="/home/mariussw/ARC_Project Dropbox/Marius Wishman/Apps/Overleaf/TJ-project/bib.bib"
if [ $# -eq 2 ]; then
location="$2"
fi
# Check crossref.org for the bib citation.
curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n" > $HOME/.cache/bibref
cat $HOME/.cache/bibref >> "$location"
echo 'I wrote this to the bib:'
cat $HOME/.cache/bibref
read -r -p "Would you like to edit this? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
$EDITOR "$location"
;;
*)
;;
esac
# rsync to dropbox
#rsync -a "$location" $HOME/ARC_Project\ Dropbox/Marius\ Wishman/Apps/Overleaf/Communal\ violence\ and\ precolonial\ states/
# Download from scihub
read -r -p "Download? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
scihubtj $doi
;;
*)
;;
esac