-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspc-tool.sh
executable file
·95 lines (84 loc) · 1.74 KB
/
spc-tool.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
red=1
green=148
blue=147
function color {
if [ -n "$1" ]; then
echo -e -n "\033[38;5;$1m"
else
echo -e -n "\033[39m"
fi
}
function message {
color $green
echo $1
color
}
HELP=''
VERBOSE=''
INPUT=''
OUTPUT=''
TEMPLATE='yes'
while getopts hi:o:vt option; do
case $option in
h) HELP='yes';;
i) INPUT=${OPTARG};;
o) OUTPUT=${OPTARG};;
v) VERBOSE='yes';;
t) TEMPLATE='';;
esac
done
if [ ! -z $HELP ]; then
color $blue
echo "Usage: $0 [-h] [-i <input file>] [-o <output file>] [-v] [<directories and files>]"
echo
color
exit
fi
if [ -z $INPUT ]; then
file=.list.temp
echo > $file
for arg in $@; do
if [[ "$arg" == -* ]]; then
continue
fi
for x in `find $arg -name \*.tex`; do
if [ `basename $x` != 'template.tex' ] || [ -z $TEMPLATE ]; then
readlink -m $x >> $file
fi
done
done
cat $file | sort -V | uniq > uniq-$file
mv uniq-$file $file
else
file=$INPUT
fi
message "Compiling following files:"
logfile=.list.log
echo > $logfile
for x in `cat $file`; do
echo $x
echo ":::::::::::: $x :::::::::::" >> $logfile
if [ ! -z $VERBOSE ]; then
color $red
(cd `dirname $x`; pdfcslatex `basename $x`)
color
else
(cd `dirname $x`; pdfcslatex `basename $x`) >> $logfile
fi
done
echo `cat $file | sed -e 's/\.tex/\.pdf/'` > arg-$file
mv arg-$file $file
if [ -z $OUTPUT ]; then
OUTPUT='result.pdf'
fi
message "Generating file '$OUTPUT'"
if [ `wc -w < $file` == 1 ]; then
cp `cat $file` $OUTPUT.pdf
else
pdfunite `cat $file` $OUTPUT
fi
if [ -z $INPUT ]; then
rm $file
fi
rm $logfile