-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tex.sh
executable file
·97 lines (76 loc) · 1.4 KB
/
create_tex.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
96
#!/bin/bash
dir=$(pwd)
name="report_temp.tex"
report=0
subj=""
subjName=""
file=""
num=1
declare -A subjects=(
["INF-2202"]="Concurrent Data-intensive Programming"
["INF-2300"]="Computer Network"
["INF-2700"]="Databases Systems"
)
parse_file(){
subj=${subj^^}
subjName=${subjects[$subj]}
if [ -z subjName ]; then
printf "Could not find $subj"
exit 1
fi
sed -i "s/\<Subject\>/${subj}/g" $file
sed -i "s/\<Header\>/${subj}/g" $file
sed -i "s/Name/${subjName}/g" $file
sed -i "s/Num/${num}/g" $file
}
set_up(){
cd ~/Templates
check=$(find . -maxdepth 1 -name $name)
if [ -z $check ]; then
printf "Could not find report template \n"
exit 1
fi
curdir=$(pwd)
if [ $curdir = $dir ]; then
cp $name $new_name".tex"
else
echo "not same dir"
cp $curdir/$name $dir
mv $dir/$name $dir/$new_name".tex"
file=$dir/$new_name".tex"
fi
if [ ! -z "$subj" ];then
parse_file
fi
}
usage(){
echo "Usage:
Required:
-n or --name [filename]
Optional:
-r for report (default)
-s or --sub to specify subject
-num or --num to specify Assignment number
"
}
if [ $# = 0 ];then
usage
exit 1
fi
while [ "$1" != "" ]; do
case $1 in
-n | --name) shift; new_name=$1;;
-r | --report) report=1;;
-h | --help) usage;;
-s | --sub) shift; subj=$1;;
-num | --num) shift; num=$1;;
* ) usage;;
esac
shift
done
echo $new_name
if [ ! -z "$new_name" ];then
set_up
else
usage
fi