-
Notifications
You must be signed in to change notification settings - Fork 1
/
courses
146 lines (119 loc) · 3.86 KB
/
courses
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
#
# functions to manage course notes
#
#-----------------------------------------------------------------------------#
# DEFINITIONS #
#-----------------------------------------------------------------------------#
PUBLISH_TEMPLATE="eisvogel"
#-----------------------------------------------------------------------------#
# FUNCTIONS
#-----------------------------------------------------------------------------#
init-course () {
# Check if the course files exist
if [ ! -f $COURSES_FILE ]; then
touch $COURSES_FILE
fi
# Get curricular unit name
course_name=$( basename "$(pwd)" )
# Check if there is already a Note directory
if [ -d "Notes" ]; then
echo -ne "${RED}ERROR!${NC} There is already a directory for notes in this folder. ${LRED}Aborted.${NC}\n"
exit 1
fi
# Create Notes directory structure
mkdir Notes
cd Notes
mkdir raw metadata pdf pictures
# Introduce new directory to the available directory structure
notes_dir="$(pwd)"
echo -ne "$1 |$notes_dir\n" >> $COURSES_FILE
# Create .gitignore
echo -e "# Compressed files
*.tar
*.tar.bz2
# Vim swap files
*.swp
*.swo
# Tex compilation results
*.aux
*.log
# Temporary hidden files from open files
.fuse_hidden*" \
> .gitignore
# Create README
echo -e "$course_name Notes" > README.md
git init
git add raw metadata pdf pictures .gitignore README.md
git commit -m "First commit. Added basic directory structure."
}
course-new-raw-note () {
# Check if the courses list files exists and if the course is valid
if [ ! -f $COURSES_FILE ]; then
echo -e "${RED}ERROR!${NC} No course file found. ${LRED}Aborting.${NC}"
exit 1
elif ! grep -w "$2" "$COURSES_FILE" ; then
echo -e "${RED}ERROR!${NC} The course is not listed in the course file. ${LRED}Aborting.${NC}"
exit 1
fi
# Get course path from courses list
course_path="$(grep -w $2 "$COURSES_FILE" | cut -d\| -f2)"
cd "$course_path"
if [ $1 == "-t" ]; then # Theoretical
filename="[T]$(date +"%d-%m").md"
type="Theoretical"
elif [ "$1" == "-p" ]; then # Pratical
filename="[P]$(date +"%d-%m").md"
type="Pratical"
elif [ "$1" == "-o" ]; then # Ordinary notes
filename="[O]$(date +"%d-%m").md"
type="Ordinary Notes"
fi
if [ ! -f "$filename" ]; then
vim "+ normal G $" raw/$filename
else
vim raw/"$filename"
fi
# Commit
git add raw/"$filename"
git commit -m "[RAW] $type notes for class on $(date +"%d %B")"
# Print TODOs
echo -ne "\n${CYAN}**TODO**${NC} list on this note:\n"
grep -inw "__TODO__" raw/"$filename"
echo -ne "\n"
# Print statistics about file
lines=$(wc -l raw/"$filename" | cut -d" " -f1)
words=$(wc -w raw/"$filename" | cut -d" " -f1)
characters=$(wc -c raw/"$filename" | cut -d" " -f1)
printf "\n${RED}**STATISTICS**${NC}\nLines: %s\nWords: %s\nCharacters: %s\n" "$lines" "$words" "$characters"
}
list-courses () {
# Check if the course files exist
if [ ! -f $COURSES_FILE ]; then
echo "${RED}ERROR!${NC} No course file found. ${LRED}Aborting.${NC}"
exit 1
fi
sed "s/|/stored\ in:\ /g" <<< cat $COURSES_FILE
}
change-directory () {
# Check if the courses list files exists and if the course is valid
if [ ! -f $COURSES_FILE ]; then
echo -e "${RED}ERROR!${NC} No course file found. ${LRED}Aborting.${NC}"
exit 1
elif ! grep -w "$1" "$COURSES_FILE" ; then
echo -e "${RED}ERROR!${NC} The course is not listed in the course file. ${LRED}Aborting.${NC}"
exit 1
fi
# Get course path from courses list
course_path="$(grep -w "$1" "$COURSES_FILE" | cut -d\| -f2)"
cd "$course_path"
exec bash
}
publish () {
filename=$(basename "$1" .md)
if [ -f metadata/"$filename.yaml" ]; then
pandoc "metadata/$filename.yaml" "$1" -o "pdf/$filename.pdf" --latex-engine=xelatex --template=$PUBLISH_TEMPLATE --toc --listings --highlight-style=tango -N
else
pandoc "$1" -o "pdf/$filename.pdf" --latex-engine=xelatex --template=$PUBLISH_TEMPLATE --toc --listings --highlight-style=tango -N
fi
}