-
Notifications
You must be signed in to change notification settings - Fork 0
/
showbib
executable file
·77 lines (65 loc) · 2.07 KB
/
showbib
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Usage: showbib [-l|--latex] [BIBFILE_NAME]
# showbib shows a bib file. Problems, if exist, will be displayed. It calls ./python/bibtex_check.py.
# If -l|--latex is present, then showbib interprets the file as a BibLaTeX file; otherwise,
# checkbib will try to decide the type of the input file and check it accordingly; if the type cannot
# the decided, then checkbib interprets it as a BibTeX file.
WEBBROWSER="google-chrome --new-window --start-maximized " # The web browser for viewing html
BIBLATEX=0
USER_SPECIFY_LATEX=0
BIBFILE=""
if [[ $# -gt 2 ]]; then
printf "Usage: showbib [-l|--latex] [BIBFILE_NAME] \n"
exit 1
fi
# Parse the arguments
while [[ -n "$1" ]]; do
case "$1" in
-l|--latex)
BIBLATEX=1
USER_SPECIFY_LATEX=1
;;
*)
if [[ -z "$BIBFILE" ]]; then
BIBFILE="$1"
fi
;;
esac
shift
done
# Get the name of the bib file with full path.
# If the input is empty, then use the latest bib file under the current directory.
if [[ -z "$BIBFILE" ]]; then
BIBFILE=`find ./ -maxdepth 1 -type f -name "*.bib" -print0 | xargs -r -0 ls -1 -t | head -1`
fi
BIBFILE=`readlink -f $BIBFILE`
if [[ -z "${BIBFILE##*/}" ]]; then
echo ""
echo "No bib file found."
echo ""
exit 2
elif [[ ! -f "$BIBFILE" ]]; then
echo ""
echo "$BIBFILE does not exist."
echo ""
exit 2
fi
# Decide whether this is a BibLaTeX file or a BibTeX file.
if grep -q "journaltitle\s*=\s*\|date\s*=\s*\|location\s*=\s*\|type\s*=\s*" $BIBFILE ; then
# This is likely a BibLaTeX file.
BIBLATEX=1
elif [[ $USER_SPECIFY_LATEX != 1 ]]; then
# This seems not a BibLaTeX file and the user does not say so.
BIBLATEX=0
fi
# Get the directory where this script resides
TEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BCPYOUTPUT="bibtex_check.html"
if [[ $BIBLATEX -eq 1 ]] ; then
BCPY="python3 $TEXTOOLSDIR/python/bibtex_check.py -o $BCPYOUTPUT -l -b"
else
BCPY="python3 $TEXTOOLSDIR/python/bibtex_check.py -o $BCPYOUTPUT -b"
fi
$BCPY $BIBFILE > /dev/null
$WEBBROWSER bibtex_check.html
exit 0