Commit
+273 -0 +/-10 browse
1 | diff --git a/.gitignore b/.gitignore |
2 | new file mode 100644 |
3 | index 0000000..69fa449 |
4 | --- /dev/null |
5 | +++ b/.gitignore |
6 | @@ -0,0 +1 @@ |
7 | + _build/ |
8 | diff --git a/.merlin b/.merlin |
9 | new file mode 100644 |
10 | index 0000000..a469268 |
11 | --- /dev/null |
12 | +++ b/.merlin |
13 | @@ -0,0 +1,138 @@ |
14 | + EXCLUDE_QUERY_DIR |
15 | + B /home/kevin/.opam/default/lib/base |
16 | + B /home/kevin/.opam/default/lib/base/base_internalhash_types |
17 | + B /home/kevin/.opam/default/lib/base/caml |
18 | + B /home/kevin/.opam/default/lib/base/md5 |
19 | + B /home/kevin/.opam/default/lib/base/shadow_stdlib |
20 | + B /home/kevin/.opam/default/lib/base_bigstring |
21 | + B /home/kevin/.opam/default/lib/base_quickcheck |
22 | + B /home/kevin/.opam/default/lib/bigarray-compat |
23 | + B /home/kevin/.opam/default/lib/bin_prot |
24 | + B /home/kevin/.opam/default/lib/bin_prot/shape |
25 | + B /home/kevin/.opam/default/lib/bytes |
26 | + B /home/kevin/.opam/default/lib/core |
27 | + B /home/kevin/.opam/default/lib/core/error_checking_mutex |
28 | + B /home/kevin/.opam/default/lib/core_kernel |
29 | + B /home/kevin/.opam/default/lib/core_kernel/base_for_tests |
30 | + B /home/kevin/.opam/default/lib/core_kernel/caml_unix |
31 | + B /home/kevin/.opam/default/lib/core_kernel/flags |
32 | + B /home/kevin/.opam/default/lib/core_kernel/version_util |
33 | + B /home/kevin/.opam/default/lib/cstruct |
34 | + B /home/kevin/.opam/default/lib/ctypes |
35 | + B /home/kevin/.opam/default/lib/ezjsonm |
36 | + B /home/kevin/.opam/default/lib/fieldslib |
37 | + B /home/kevin/.opam/default/lib/fmt |
38 | + B /home/kevin/.opam/default/lib/hex |
39 | + B /home/kevin/.opam/default/lib/integers |
40 | + B /home/kevin/.opam/default/lib/jane-street-headers |
41 | + B /home/kevin/.opam/default/lib/jsonm |
42 | + B /home/kevin/.opam/default/lib/logs |
43 | + B /home/kevin/.opam/default/lib/parsexp |
44 | + B /home/kevin/.opam/default/lib/ppx_assert/runtime-lib |
45 | + B /home/kevin/.opam/default/lib/ppx_bench/runtime-lib |
46 | + B /home/kevin/.opam/default/lib/ppx_compare/runtime-lib |
47 | + B /home/kevin/.opam/default/lib/ppx_enumerate/runtime-lib |
48 | + B /home/kevin/.opam/default/lib/ppx_expect/collector |
49 | + B /home/kevin/.opam/default/lib/ppx_expect/common |
50 | + B /home/kevin/.opam/default/lib/ppx_expect/config |
51 | + B /home/kevin/.opam/default/lib/ppx_expect/config_types |
52 | + B /home/kevin/.opam/default/lib/ppx_hash/runtime-lib |
53 | + B /home/kevin/.opam/default/lib/ppx_here/runtime-lib |
54 | + B /home/kevin/.opam/default/lib/ppx_inline_test/config |
55 | + B /home/kevin/.opam/default/lib/ppx_inline_test/runtime-lib |
56 | + B /home/kevin/.opam/default/lib/ppx_module_timer/runtime |
57 | + B /home/kevin/.opam/default/lib/ppx_sexp_conv/runtime-lib |
58 | + B /home/kevin/.opam/default/lib/result |
59 | + B /home/kevin/.opam/default/lib/rresult |
60 | + B /home/kevin/.opam/default/lib/seq |
61 | + B /home/kevin/.opam/default/lib/sexplib |
62 | + B /home/kevin/.opam/default/lib/sexplib/unix |
63 | + B /home/kevin/.opam/default/lib/sexplib0 |
64 | + B /home/kevin/.opam/default/lib/spawn |
65 | + B /home/kevin/.opam/default/lib/splittable_random |
66 | + B /home/kevin/.opam/default/lib/stdio |
67 | + B /home/kevin/.opam/default/lib/stdlib-shims |
68 | + B /home/kevin/.opam/default/lib/time_now |
69 | + B /home/kevin/.opam/default/lib/timezone |
70 | + B /home/kevin/.opam/default/lib/typerep |
71 | + B /home/kevin/.opam/default/lib/uchar |
72 | + B /home/kevin/.opam/default/lib/uutf |
73 | + B /home/kevin/.opam/default/lib/variantslib |
74 | + B /home/kevin/.opam/default/lib/yaml |
75 | + B /home/kevin/.opam/default/lib/yaml/bindings |
76 | + B /home/kevin/.opam/default/lib/yaml/bindings/types |
77 | + B /home/kevin/.opam/default/lib/yaml/c |
78 | + B /home/kevin/.opam/default/lib/yaml/ffi |
79 | + B /home/kevin/.opam/default/lib/yaml/types |
80 | + B /usr/lib/ocaml |
81 | + B /usr/lib/ocaml/threads |
82 | + B _build/default/.main.eobjs/byte |
83 | + S /home/kevin/.opam/default/lib/base |
84 | + S /home/kevin/.opam/default/lib/base/base_internalhash_types |
85 | + S /home/kevin/.opam/default/lib/base/caml |
86 | + S /home/kevin/.opam/default/lib/base/md5 |
87 | + S /home/kevin/.opam/default/lib/base/shadow_stdlib |
88 | + S /home/kevin/.opam/default/lib/base_bigstring |
89 | + S /home/kevin/.opam/default/lib/base_quickcheck |
90 | + S /home/kevin/.opam/default/lib/bigarray-compat |
91 | + S /home/kevin/.opam/default/lib/bin_prot |
92 | + S /home/kevin/.opam/default/lib/bin_prot/shape |
93 | + S /home/kevin/.opam/default/lib/bytes |
94 | + S /home/kevin/.opam/default/lib/core |
95 | + S /home/kevin/.opam/default/lib/core/error_checking_mutex |
96 | + S /home/kevin/.opam/default/lib/core_kernel |
97 | + S /home/kevin/.opam/default/lib/core_kernel/base_for_tests |
98 | + S /home/kevin/.opam/default/lib/core_kernel/caml_unix |
99 | + S /home/kevin/.opam/default/lib/core_kernel/flags |
100 | + S /home/kevin/.opam/default/lib/core_kernel/version_util |
101 | + S /home/kevin/.opam/default/lib/cstruct |
102 | + S /home/kevin/.opam/default/lib/ctypes |
103 | + S /home/kevin/.opam/default/lib/ezjsonm |
104 | + S /home/kevin/.opam/default/lib/fieldslib |
105 | + S /home/kevin/.opam/default/lib/fmt |
106 | + S /home/kevin/.opam/default/lib/hex |
107 | + S /home/kevin/.opam/default/lib/integers |
108 | + S /home/kevin/.opam/default/lib/jane-street-headers |
109 | + S /home/kevin/.opam/default/lib/jsonm |
110 | + S /home/kevin/.opam/default/lib/logs |
111 | + S /home/kevin/.opam/default/lib/parsexp |
112 | + S /home/kevin/.opam/default/lib/ppx_assert/runtime-lib |
113 | + S /home/kevin/.opam/default/lib/ppx_bench/runtime-lib |
114 | + S /home/kevin/.opam/default/lib/ppx_compare/runtime-lib |
115 | + S /home/kevin/.opam/default/lib/ppx_enumerate/runtime-lib |
116 | + S /home/kevin/.opam/default/lib/ppx_expect/collector |
117 | + S /home/kevin/.opam/default/lib/ppx_expect/common |
118 | + S /home/kevin/.opam/default/lib/ppx_expect/config |
119 | + S /home/kevin/.opam/default/lib/ppx_expect/config_types |
120 | + S /home/kevin/.opam/default/lib/ppx_hash/runtime-lib |
121 | + S /home/kevin/.opam/default/lib/ppx_here/runtime-lib |
122 | + S /home/kevin/.opam/default/lib/ppx_inline_test/config |
123 | + S /home/kevin/.opam/default/lib/ppx_inline_test/runtime-lib |
124 | + S /home/kevin/.opam/default/lib/ppx_module_timer/runtime |
125 | + S /home/kevin/.opam/default/lib/ppx_sexp_conv/runtime-lib |
126 | + S /home/kevin/.opam/default/lib/result |
127 | + S /home/kevin/.opam/default/lib/rresult |
128 | + S /home/kevin/.opam/default/lib/seq |
129 | + S /home/kevin/.opam/default/lib/sexplib |
130 | + S /home/kevin/.opam/default/lib/sexplib/unix |
131 | + S /home/kevin/.opam/default/lib/sexplib0 |
132 | + S /home/kevin/.opam/default/lib/spawn |
133 | + S /home/kevin/.opam/default/lib/splittable_random |
134 | + S /home/kevin/.opam/default/lib/stdio |
135 | + S /home/kevin/.opam/default/lib/stdlib-shims |
136 | + S /home/kevin/.opam/default/lib/time_now |
137 | + S /home/kevin/.opam/default/lib/timezone |
138 | + S /home/kevin/.opam/default/lib/typerep |
139 | + S /home/kevin/.opam/default/lib/uchar |
140 | + S /home/kevin/.opam/default/lib/uutf |
141 | + S /home/kevin/.opam/default/lib/variantslib |
142 | + S /home/kevin/.opam/default/lib/yaml |
143 | + S /home/kevin/.opam/default/lib/yaml/bindings |
144 | + S /home/kevin/.opam/default/lib/yaml/bindings/types |
145 | + S /home/kevin/.opam/default/lib/yaml/c |
146 | + S /home/kevin/.opam/default/lib/yaml/ffi |
147 | + S /home/kevin/.opam/default/lib/yaml/types |
148 | + S /usr/lib/ocaml |
149 | + S /usr/lib/ocaml/threads |
150 | + S . |
151 | + FLG -open Dune__exe -w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths -keep-locs -w -32 -w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths -keep-locs -w -27 |
152 | diff --git a/README.md b/README.md |
153 | new file mode 100644 |
154 | index 0000000..fbb9dd5 |
155 | --- /dev/null |
156 | +++ b/README.md |
157 | @@ -0,0 +1,34 @@ |
158 | + # Note |
159 | + |
160 | + `Note` is a simple CLI based note taking application. |
161 | + |
162 | + ## The Anatonmy of a Note |
163 | + |
164 | + A note is simply a text file, often written in Markdown, that has `front-matter` at the head of |
165 | + the document. Front-matter was popularized by static html generators such as Jekyll and Hugo. |
166 | + Everything above the front-matter section will be discarded and everything below it is considered |
167 | + the body of a given note. |
168 | + |
169 | + ```markdown |
170 | + --- |
171 | + title: This is a Note |
172 | + tags: ["misc", "note taking"] |
173 | + --- |
174 | + |
175 | + # Hello World! |
176 | + |
177 | + Today will be a nice day. |
178 | + ``` |
179 | + |
180 | + ## Configuration |
181 | + |
182 | + The behavior of `note` can be configured with yaml file stored in `~/.config/note/config.yaml`. |
183 | + |
184 | + ```yaml |
185 | + state_dir: ~/local/share/note/state |
186 | + lock_file: ~/.local/share/note/note.lock |
187 | + ``` |
188 | + |
189 | + ## State Dir |
190 | + |
191 | + Notes are stored as flat files in the `state_dir` directory where each note is a flat file. |
192 | diff --git a/db/task-1.md b/db/task-1.md |
193 | new file mode 100644 |
194 | index 0000000..041587c |
195 | --- /dev/null |
196 | +++ b/db/task-1.md |
197 | @@ -0,0 +1,6 @@ |
198 | + --- |
199 | + title: Hello World |
200 | + tags: ["fuu", "bar"] |
201 | + --- |
202 | + |
203 | + This is a task |
204 | diff --git a/db/task-2.md b/db/task-2.md |
205 | new file mode 100644 |
206 | index 0000000..67025d7 |
207 | --- /dev/null |
208 | +++ b/db/task-2.md |
209 | @@ -0,0 +1,4 @@ |
210 | + --- |
211 | + title: A Very Important Task To Complete |
212 | + tags: ["x", "y", "z"] |
213 | + --- |
214 | diff --git a/db/task-3.md b/db/task-3.md |
215 | new file mode 100644 |
216 | index 0000000..218954b |
217 | --- /dev/null |
218 | +++ b/db/task-3.md |
219 | @@ -0,0 +1,4 @@ |
220 | + --- |
221 | + title: Yet Another Important Task That Must Be Completed |
222 | + tags: ["one", "two", "three"] |
223 | + --- |
224 | diff --git a/dune b/dune |
225 | new file mode 100644 |
226 | index 0000000..948c326 |
227 | --- /dev/null |
228 | +++ b/dune |
229 | @@ -0,0 +1,6 @@ |
230 | + (executable |
231 | + (name main) |
232 | + (libraries base core ezjsonm stdio yaml)) |
233 | + (env |
234 | + (dev |
235 | + (flags (:standard -w -32)(:standard -w -27)))) |
236 | diff --git a/dune-project b/dune-project |
237 | new file mode 100644 |
238 | index 0000000..e8b8374 |
239 | --- /dev/null |
240 | +++ b/dune-project |
241 | @@ -0,0 +1 @@ |
242 | + (lang dune 2.6) |
243 | diff --git a/main.ml b/main.ml |
244 | new file mode 100644 |
245 | index 0000000..9698179 |
246 | --- /dev/null |
247 | +++ b/main.ml |
248 | @@ -0,0 +1,36 @@ |
249 | + open Core |
250 | + |
251 | + let list_notes = |
252 | + Command.basic ~summary:"List Notes" |
253 | + Command.Param.( |
254 | + map (anon (maybe ("filter" %: string))) ~f:( |
255 | + fun filter_str () -> |
256 | + let notes = Note.read_tasks "db" in |
257 | + List.iter ~f: (fun x -> Note.display_task x) notes; |
258 | + ) |
259 | + ) |
260 | + |
261 | + |
262 | + let edit_note = |
263 | + Command.basic ~summary: "Create a New Note or Edit An Existing Note" |
264 | + Command.Param.( |
265 | + map (anon (maybe ("name" %: string))) ~f:( |
266 | + fun name () -> |
267 | + print_endline "creating a new note" ; |
268 | + ) |
269 | + ) |
270 | + |
271 | + |
272 | + let delete_note = |
273 | + Command.basic ~summary: "Create a New Note" |
274 | + Command.Param.( |
275 | + map (anon (maybe ("name" %: string))) ~f:( |
276 | + fun name () -> |
277 | + print_endline "creating a new note" ; |
278 | + ) |
279 | + ) |
280 | + |
281 | + let command = Command.group ~summary:"list" [ ("list", list_notes) ] |
282 | + |
283 | + let () = |
284 | + Command.run command |
285 | diff --git a/note.ml b/note.ml |
286 | new file mode 100644 |
287 | index 0000000..e7f2610 |
288 | --- /dev/null |
289 | +++ b/note.ml |
290 | @@ -0,0 +1,43 @@ |
291 | + open Core |
292 | + open Stdio |
293 | + |
294 | + type task = { title : string; tags : string list } |
295 | + |
296 | + let get_title dict = |
297 | + let title = List.find ~f:(fun (key, _) -> equal_string key "title") dict in |
298 | + match title with Some (_, v) -> Ezjsonm.get_string v | None -> "" |
299 | + |
300 | + let get_tags dict = |
301 | + let title = List.find ~f:(fun (key, _) -> equal_string key "tags") dict in |
302 | + match title with Some (_, v) -> Ezjsonm.get_strings v | None -> [] |
303 | + |
304 | + let get_front_matter task_str = |
305 | + let indexes = |
306 | + String.substr_index_all ~may_overlap:true ~pattern:"---" task_str |
307 | + in |
308 | + if List.length indexes >= 2 then |
309 | + let meta_str = |
310 | + String.slice task_str |
311 | + (List.nth_exn indexes 0 + 3) |
312 | + (List.nth_exn indexes 1) |
313 | + in |
314 | + let value = Yaml.of_string_exn meta_str in |
315 | + let dict = Ezjsonm.get_dict value in |
316 | + Some { title = get_title dict; tags = get_tags dict } |
317 | + else None |
318 | + |
319 | + let read_task path = |
320 | + let task_str = In_channel.read_all path in |
321 | + get_front_matter task_str |
322 | + |
323 | + let read_tasks path = |
324 | + let files = Sys.ls_dir path in |
325 | + let paths = List.map ~f:(fun p -> sprintf "%s/%s" path p) files in |
326 | + List.map ~f:read_task paths |
327 | + |
328 | + let display_task task = |
329 | + match task with |
330 | + | Some t -> |
331 | + print_endline t.title; |
332 | + print_endline (String.concat ~sep:" | " t.tags) |
333 | + | None -> print_endline "bad task :(" |