voidrice/.scripts/tools/getbib

15 lines
426 B
Text
Raw Normal View History

2018-12-01 19:34:14 +00:00
#!/bin/sh
2019-04-10 12:11:55 +00:00
[ -z "$1" ] && echo "Give either a pdf file or a DOI as an argument." && exit
2018-07-03 14:55:55 +00:00
2019-04-10 12:11:55 +00:00
if [ -f "$1" ]; then
# Try to get DOI from pdfinfo or pdftotext output.
2018-12-01 19:34:14 +00:00
doi=$(pdfinfo "$1" | grep -io "doi:.*") ||
2019-04-10 12:11:55 +00:00
doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi:.*" -m 1) ||
2018-07-03 14:55:55 +00:00
exit 1
2018-12-01 19:34:14 +00:00
else
doi="$1"
fi
2018-07-03 14:55:55 +00:00
# Check crossref.org for the bib citation.
2019-04-10 12:11:55 +00:00
curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n"