-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim_md_notes
executable file
·67 lines (53 loc) · 3.46 KB
/
vim_md_notes
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
#!/bin/sh
NOTEBOOK_MD_DIR="$HOME/Documents/Notebooks"
NOTEBOOK_PDF_DIR="$HOME/Documents/Notebooks/pdf"
shopt -s nullglob
NOTEBOOKS=($NOTEBOOK_MD_DIR/*.md)
PDF_LIST=($NOTEBOOK_PDF_DIR/*.pdf)
newEntry() {
NEW_ENTRY=$(printf '%s\n' "${NOTEBOOKS[@]}" | awk -F "/" '{print $NF}' | awk -F "." '{print $1}' |dmenu -i -c -l 20 -p "Notebooks: ")
[[ ! "$NEW_ENTRY" ]] && exit 1
[[ ! -f "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" ]] && ( echo -e "---\ntitle: $NEW_ENTRY\ngeometry: margin=3cm\n---" > "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md")
[[ ! -f "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" ]] && ( touch "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf")
alacritty -t Notes -e nvim -c "norm G2o" \
-c "norm zz" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md"
case "$NEW_ENTRY" in
Bash ) pandoc --indented-code-classes=bash --highlight-style zenburn -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
Python ) pandoc --indented-code-classes=python --highlight-style zenburn -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
Julia ) pandoc --indented-code-classes=julia --highlight-style zenburn -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
Cpp ) pandoc --indented-code-classes=cpp --highlight-style zenburn -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
C ) pandoc --indented-code-classes=c --highlight-style zenburn -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
Haskell ) pandoc --indented-code-classes=haskell --highlight-style zenburn -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
Perl ) pandoc --indented-code-classes=perl --highlight-style zenburn -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
Lisp ) pandoc --indented-code-classes=lisp --highlight-style zenburn -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
* ) pandoc -o "$NOTEBOOK_PDF_DIR/$NEW_ENTRY.pdf" "$NOTEBOOK_MD_DIR/$NEW_ENTRY.md" &;;
esac
exit 1
}
deleteNotebook() {
TO_REMOVE=$(printf '%s\n' "${NOTEBOOKS[@]}" | awk -F "/" '{print $NF}' | awk -F "." '{print $1}' | dmenu -i -c -l 20 -p "Notebook to delete: ")
[[ ! "$TO_REMOVE" ]] && exit 1
SAVE_PDF=$(echo -e "Yes\nNo" | dmenu -i -c -l 2 -p "Archive the pdf? ")
[[ ! "$SAVE_PDF" ]] && exit 1
[[ -f "$NOTEBOOK_MD_DIR/$TO_REMOVE.md" ]] && rm "$NOTEBOOK_MD_DIR/$TO_REMOVE.md"
if [[ "$SAVE_PDF" == "Yes" ]]; then
[[ -f "$NOTEBOOK_PDF_DIR/$TO_REMOVE.pdf" ]] && mv "$NOTEBOOK_PDF_DIR/$TO_REMOVE.pdf" "$NOTEBOOK_PDF_DIR/Archive/$TO_REMOVE.pdf"
elif [[ "$SAVE_PDF" == "No" ]]; then
[[ -f "$NOTEBOOK_PDF_DIR/$TO_REMOVE.pdf" ]] && rm "$NOTEBOOK_PDF_DIR/$TO_REMOVE.pdf"
fi
exit 1
}
viewPdf() {
VIEW_PDF=$(printf '%s\n' "${PDF_LIST[@]}" | awk -F "/" '{print $NF}' | dmenu -i -c -l 20 -p "PDF Notebooks: ")
[[ ! "$VIEW_PDF" ]] && exit 1
zathura "$NOTEBOOK_PDF_DIR/$VIEW_PDF"
}
while getopts "vnd" opt
do
case ${opt} in
v ) viewPdf;;
n ) newEntry;; # To create a new notebook, just type a name that is not there and hit enter
d ) deleteNotebook;;
* ) echo -e "Invalid option\n-v\tView pdf version\n-n\tWrite a new entry into one of the notes\n-d\tDelete a note"
esac
done