-
Notifications
You must be signed in to change notification settings - Fork 1
/
logbook
executable file
·203 lines (167 loc) · 4.21 KB
/
logbook
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
#
#
# Exit script if an undefined variable is used and when a command exits with a non-zero status
set -u -e
set -o pipefail
#-----------------------------------------------------------------------------#
# COLOURS #
#-----------------------------------------------------------------------------#
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BROWN='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LGRAY='\033[0;37m'
DGRAY='\033[1;30m'
LRED='\033[1;31m'
LGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LBLUE='\033[1;34m'
LPURPLE='\033[1;35m'
LCYAN='\033[1;36m'
WHITE='\033[1;37m'
NC='\033[0m' #No Color
#-----------------------------------------------------------------------------#
# PATHS #
#-----------------------------------------------------------------------------#
LOGBOOK_PATH=/media/martinspedro/DATA/.logbook
COURSES_FILE=$LOGBOOK_PATH/courses_list
JOURNAL_PATH=$LOGBOOK_PATH/journal
DOC_PATH=$LOGBOOK_PATH/documents
#-----------------------------------------------------------------------------#
# SOURCE FILES #
#-----------------------------------------------------------------------------#
source journal
source courses
source documents
#-----------------------------------------------------------------------------#
# HELP MESSAGE #
#-----------------------------------------------------------------------------#
help-message () {
echo -ne "Logbook v0.1
USAGE: logbook <options> <args>\n
options
-j|--journal: Creates a new journal entry.
-t|--tag <tag_name>: Fetch all journal entries by <tag_name>
-q|--quote: Fetch all quotes in journal entries
-b|--browse-journal: Browse through journal entries
--init-course: Initializates a new course in the current directory.
-c|--course: Adds a new raw note to a previously created course unit.
-p|--publish: Publish raw/curated note, or any given markdown file
-lc|--list-courses: Lists all courses
--new-doc: Initializes a new document ${RED} DEPRECATED${NC} Use --doc instead
--doc: Creates and/or edits an document
-s|--symbolic-link: Creates a symbolic link in the current directory to a document
-ld|--list-documents: Lists all created documents
-h|--help: Shows this menu.\n"
}
#-----------------------------------------------------------------------------#
# SCRIPT AREA #
#-----------------------------------------------------------------------------#
if [ $# -ge 1 ] && [ $# -le 3 ]; then
current_path=$(pwd)
case $1 in
-j|--journal)
new-journal-entry
;;
-t|--tag)
if [ $# -eq 2 ]; then
search-journal "$2"
else
echo "USAGE: logbook -t|--tag <tag_name>"
exit 1
fi
;;
-q|--quote)
if [ $# -eq 1 ]; then
search-journal ">"
else
echo "USAGE: logbook -q|--quote"
exit 1
fi
;;
-b|--browse-journal)
browse-entries
;;
--init-course)
if [ $# -eq 2 ]; then
init-course $2
else
echo "USAGE: logbook --init-course <directory key>"
exit 1
fi
;;
-c|--course)
if [ $# -eq 3 ]; then
course-new-raw-note $2 $3
else
echo "USAGE: logbook -c|--course <note type> <course name>"
exit 1
fi
;;
-p|--publish)
if [ $# -eq 2 ]; then
publish $2
else
echo "USAGE: logbook -p|--publish <note filename>"
exit 1
fi
;;
-lc|--list-courses)
list-courses
;;
-cd)
if [ $# -eq 2 ]; then
change-directory $2
else
echo "USAGE: logbook -cd <course name>"
exit 1
fi
;;
--new-doc)
if [ $# -eq 2 ]; then
new-doc $2
else
echo "USAGE: logbook --new-doc <new document name>"
exit 1
fi
;;
--doc)
if [ $# -eq 2 ]; then
open-doc $2
else
echo "USAGE: logbook --doc <document name>"
exit 1
fi
;;
-s|--symbolic-link)
if [ $# -eq 2 ]; then
create-sym $2
else
echo "USAGE: logbook -s|--symbolic-link <existent document name>"
exit 1
fi
;;
-ld|--list-docs)
list-docs
;;
-h|--help)
help-message
;;
--default)
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
# Return to original path
cd "$current_path"
else
help-message
exit 1
fi