-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-note
executable file
·83 lines (67 loc) · 1.82 KB
/
create-note
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
#!/bin/sh
# _ _ ___ _ _
# __ _| | _____ _____ ___ __| | ___ _ __ / _ \| || |
# / _` | |/ _ \ \/ / __/ _ \ / _` |/ _ \ '__| | | | || |_
# | (_| | | __/> < (_| (_) | (_| | __/ | | |_| |__ _|
# \__,_|_|\___/_/\_\___\___/ \__,_|\___|_| \___/ |_|
#
# Copyright (c) 2021-2022 alexcoder04 <https://github.com/alexcoder04>
#
# creating or editing a MD file in the school folder
SCHOOL_FOLDER="$HOME/School"
. libsh || exit 1
write_template(){
if [ "$1" = "beamer" ]; then
cat >>"$filename" <<EOF
---
title: $title
author: $USER
date: $date_readable
theme:
- CambridgeUS
colortheme:
- crane
fonttheme:
- serif
aspectratio: 169
---
<++>
EOF
else
cat >>"$filename" <<EOF
---
title: $title
author: $USER
date: $date_readable
header-includes: |
\\usepackage{fancyhdr} \\pagestyle{fancy}
\\fancyhead[L]{$date_readable}
\\fancyhead[C]{\uppercase{$title}}
\\fancyhead[R]{$subject}
---
<++>
EOF
fi
}
subject="$(/bin/ls "$SCHOOL_FOLDER" | prompt_gui "Subject")"
[ -z "$subject" ] && exit 0
[ -d "$SCHOOL_FOLDER/$subject" ] || mkdir -p "$SCHOOL_FOLDER/$subject"
cd "$SCHOOL_FOLDER/$subject"
title="$(/bin/ls "$SCHOOL_FOLDER/$subject/"*.md | prompt_gui "Title")"
title_normalized="$(echo "$title" | sed 's/\s/_/g; s/\//_/g')"
this_date="$(date +%Y%m%d-%a)"
date_readable="$(date "+%a, %d.%m.%Y")"
[ -z "$title" ] && exit 0
if [ "${title##*.}" = "md" ]; then
filename="$title"
elif [ "${title##*.}" = "create" ]; then
title="${title%%.*}"
title_normalized="${title_normalized%%.*}"
filename="$this_date-$title_normalized.md"
[ -e "$filename" ] \
&& die_notify "File you are trying to create already exists"
else
filename="$this_date-$title_normalized.md"
fi
[ -e "$filename" ] || write_template "$1"
exec launch "$EDITOR" "$filename"