-
Notifications
You must be signed in to change notification settings - Fork 3
/
new
executable file
·47 lines (38 loc) · 1.01 KB
/
new
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
#!/bin/bash
# Hacky script that creates a new note file, and opens it in atom.
unquote() {
echo $@ | tr -d "\""
}
uppercase() {
echo $@ | tr '[a-z]' '[A-Z]'
}
course_info_fmt() {
course_subject=$(echo $1 | egrep -o "[a-z]+" -)
course_catalog_number=$(echo $1 | egrep -o "\d+" -)
course_info=$(curl "https://api.uwaterloo.ca/v2/courses/$course_subject/$course_catalog_number.json?key=$UW_API_KEY" 2>/dev/null)
course_title=$(unquote $(echo $course_info | jq .data.title))
echo "$(uppercase $course_subject) $course_catalog_number - $(unquote $(echo $course_info | jq .data.title))"
}
format_notes() {
echo "# $1"
echo
echo $2
echo
echo $3
echo
echo $NAME
}
# load config
source ./config.cfg
# read arguments
course_name=$1
course_info=$(course_info_fmt $course_name)
shift
note_date=$(date -j "+%m-%d-%Y")
note_path="./$TERM/$course_name/$1.md"
shift
note_title="$@"
[[ -e $note_path ]] && exit 3
# do the thing
format_notes "$note_title" "$course_info" "$note_date" > $note_path
atom $note_path