├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── interactive.sh └── src ├── args.rs ├── extensions.rs ├── lib.rs ├── main.rs ├── marks.rs ├── org ├── datetime.rs ├── header.rs └── mod.rs ├── parsers.rs ├── query.rs ├── result.rs └── utils.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "1.1.3" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "android-tzdata" 16 | version = "0.1.1" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" 19 | 20 | [[package]] 21 | name = "android_system_properties" 22 | version = "0.1.5" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" 25 | dependencies = [ 26 | "libc", 27 | ] 28 | 29 | [[package]] 30 | name = "ansi_term" 31 | version = "0.12.1" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" 34 | dependencies = [ 35 | "winapi", 36 | ] 37 | 38 | [[package]] 39 | name = "anstream" 40 | version = "0.6.18" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" 43 | dependencies = [ 44 | "anstyle", 45 | "anstyle-parse", 46 | "anstyle-query", 47 | "anstyle-wincon", 48 | "colorchoice", 49 | "is_terminal_polyfill", 50 | "utf8parse", 51 | ] 52 | 53 | [[package]] 54 | name = "anstyle" 55 | version = "1.0.10" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" 58 | 59 | [[package]] 60 | name = "anstyle-parse" 61 | version = "0.2.6" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" 64 | dependencies = [ 65 | "utf8parse", 66 | ] 67 | 68 | [[package]] 69 | name = "anstyle-query" 70 | version = "1.1.2" 71 | source = "registry+https://github.com/rust-lang/crates.io-index" 72 | checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" 73 | dependencies = [ 74 | "windows-sys 0.59.0", 75 | ] 76 | 77 | [[package]] 78 | name = "anstyle-wincon" 79 | version = "3.0.7" 80 | source = "registry+https://github.com/rust-lang/crates.io-index" 81 | checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" 82 | dependencies = [ 83 | "anstyle", 84 | "once_cell", 85 | "windows-sys 0.59.0", 86 | ] 87 | 88 | [[package]] 89 | name = "atty" 90 | version = "0.2.14" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 93 | dependencies = [ 94 | "hermit-abi", 95 | "libc", 96 | "winapi", 97 | ] 98 | 99 | [[package]] 100 | name = "autocfg" 101 | version = "1.4.0" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" 104 | 105 | [[package]] 106 | name = "bitflags" 107 | version = "1.3.2" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 110 | 111 | [[package]] 112 | name = "bumpalo" 113 | version = "3.17.0" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" 116 | 117 | [[package]] 118 | name = "bytes" 119 | version = "1.9.0" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" 122 | 123 | [[package]] 124 | name = "cc" 125 | version = "1.2.11" 126 | source = "registry+https://github.com/rust-lang/crates.io-index" 127 | checksum = "e4730490333d58093109dc02c23174c3f4d490998c3fed3cc8e82d57afedb9cf" 128 | dependencies = [ 129 | "shlex", 130 | ] 131 | 132 | [[package]] 133 | name = "cfg-if" 134 | version = "1.0.0" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 137 | 138 | [[package]] 139 | name = "chrono" 140 | version = "0.4.39" 141 | source = "registry+https://github.com/rust-lang/crates.io-index" 142 | checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" 143 | dependencies = [ 144 | "android-tzdata", 145 | "iana-time-zone", 146 | "js-sys", 147 | "num-traits", 148 | "wasm-bindgen", 149 | "windows-targets", 150 | ] 151 | 152 | [[package]] 153 | name = "clap" 154 | version = "2.34.0" 155 | source = "registry+https://github.com/rust-lang/crates.io-index" 156 | checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" 157 | dependencies = [ 158 | "ansi_term", 159 | "atty", 160 | "bitflags", 161 | "strsim 0.8.0", 162 | "textwrap", 163 | "unicode-width", 164 | "vec_map", 165 | ] 166 | 167 | [[package]] 168 | name = "clap" 169 | version = "4.5.27" 170 | source = "registry+https://github.com/rust-lang/crates.io-index" 171 | checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" 172 | dependencies = [ 173 | "clap_builder", 174 | ] 175 | 176 | [[package]] 177 | name = "clap_builder" 178 | version = "4.5.27" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" 181 | dependencies = [ 182 | "anstream", 183 | "anstyle", 184 | "clap_lex", 185 | "strsim 0.11.1", 186 | ] 187 | 188 | [[package]] 189 | name = "clap_lex" 190 | version = "0.7.4" 191 | source = "registry+https://github.com/rust-lang/crates.io-index" 192 | checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" 193 | 194 | [[package]] 195 | name = "colorchoice" 196 | version = "1.0.3" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" 199 | 200 | [[package]] 201 | name = "combine" 202 | version = "4.6.7" 203 | source = "registry+https://github.com/rust-lang/crates.io-index" 204 | checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" 205 | dependencies = [ 206 | "bytes", 207 | "memchr", 208 | ] 209 | 210 | [[package]] 211 | name = "core-foundation-sys" 212 | version = "0.8.7" 213 | source = "registry+https://github.com/rust-lang/crates.io-index" 214 | checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" 215 | 216 | [[package]] 217 | name = "crossbeam-deque" 218 | version = "0.8.6" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" 221 | dependencies = [ 222 | "crossbeam-epoch", 223 | "crossbeam-utils", 224 | ] 225 | 226 | [[package]] 227 | name = "crossbeam-epoch" 228 | version = "0.9.18" 229 | source = "registry+https://github.com/rust-lang/crates.io-index" 230 | checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" 231 | dependencies = [ 232 | "crossbeam-utils", 233 | ] 234 | 235 | [[package]] 236 | name = "crossbeam-utils" 237 | version = "0.8.21" 238 | source = "registry+https://github.com/rust-lang/crates.io-index" 239 | checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" 240 | 241 | [[package]] 242 | name = "either" 243 | version = "1.13.0" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" 246 | 247 | [[package]] 248 | name = "fuzzy-matcher" 249 | version = "0.3.7" 250 | source = "registry+https://github.com/rust-lang/crates.io-index" 251 | checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" 252 | dependencies = [ 253 | "thread_local", 254 | ] 255 | 256 | [[package]] 257 | name = "heck" 258 | version = "0.3.3" 259 | source = "registry+https://github.com/rust-lang/crates.io-index" 260 | checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" 261 | dependencies = [ 262 | "unicode-segmentation", 263 | ] 264 | 265 | [[package]] 266 | name = "hermit-abi" 267 | version = "0.1.19" 268 | source = "registry+https://github.com/rust-lang/crates.io-index" 269 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 270 | dependencies = [ 271 | "libc", 272 | ] 273 | 274 | [[package]] 275 | name = "home" 276 | version = "0.5.11" 277 | source = "registry+https://github.com/rust-lang/crates.io-index" 278 | checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" 279 | dependencies = [ 280 | "windows-sys 0.59.0", 281 | ] 282 | 283 | [[package]] 284 | name = "iana-time-zone" 285 | version = "0.1.61" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" 288 | dependencies = [ 289 | "android_system_properties", 290 | "core-foundation-sys", 291 | "iana-time-zone-haiku", 292 | "js-sys", 293 | "wasm-bindgen", 294 | "windows-core", 295 | ] 296 | 297 | [[package]] 298 | name = "iana-time-zone-haiku" 299 | version = "0.1.2" 300 | source = "registry+https://github.com/rust-lang/crates.io-index" 301 | checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" 302 | dependencies = [ 303 | "cc", 304 | ] 305 | 306 | [[package]] 307 | name = "is_terminal_polyfill" 308 | version = "1.70.1" 309 | source = "registry+https://github.com/rust-lang/crates.io-index" 310 | checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" 311 | 312 | [[package]] 313 | name = "itertools" 314 | version = "0.14.0" 315 | source = "registry+https://github.com/rust-lang/crates.io-index" 316 | checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" 317 | dependencies = [ 318 | "either", 319 | ] 320 | 321 | [[package]] 322 | name = "js-sys" 323 | version = "0.3.77" 324 | source = "registry+https://github.com/rust-lang/crates.io-index" 325 | checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" 326 | dependencies = [ 327 | "once_cell", 328 | "wasm-bindgen", 329 | ] 330 | 331 | [[package]] 332 | name = "lazy_static" 333 | version = "1.5.0" 334 | source = "registry+https://github.com/rust-lang/crates.io-index" 335 | checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" 336 | 337 | [[package]] 338 | name = "libc" 339 | version = "0.2.169" 340 | source = "registry+https://github.com/rust-lang/crates.io-index" 341 | checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" 342 | 343 | [[package]] 344 | name = "log" 345 | version = "0.4.25" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" 348 | 349 | [[package]] 350 | name = "marks" 351 | version = "0.1.0" 352 | dependencies = [ 353 | "chrono", 354 | "clap 4.5.27", 355 | "combine", 356 | "fuzzy-matcher", 357 | "itertools", 358 | "rayon", 359 | "regex", 360 | "structopt", 361 | "term", 362 | "walkdir", 363 | ] 364 | 365 | [[package]] 366 | name = "memchr" 367 | version = "2.7.4" 368 | source = "registry+https://github.com/rust-lang/crates.io-index" 369 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 370 | 371 | [[package]] 372 | name = "num-traits" 373 | version = "0.2.19" 374 | source = "registry+https://github.com/rust-lang/crates.io-index" 375 | checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" 376 | dependencies = [ 377 | "autocfg", 378 | ] 379 | 380 | [[package]] 381 | name = "once_cell" 382 | version = "1.20.2" 383 | source = "registry+https://github.com/rust-lang/crates.io-index" 384 | checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" 385 | 386 | [[package]] 387 | name = "paw" 388 | version = "1.0.0" 389 | source = "registry+https://github.com/rust-lang/crates.io-index" 390 | checksum = "09c0fc9b564dbc3dc2ed7c92c0c144f4de340aa94514ce2b446065417c4084e9" 391 | dependencies = [ 392 | "paw-attributes", 393 | "paw-raw", 394 | ] 395 | 396 | [[package]] 397 | name = "paw-attributes" 398 | version = "1.0.2" 399 | source = "registry+https://github.com/rust-lang/crates.io-index" 400 | checksum = "0f35583365be5d148e959284f42526841917b7bfa09e2d1a7ad5dde2cf0eaa39" 401 | dependencies = [ 402 | "proc-macro2", 403 | "quote", 404 | "syn 1.0.109", 405 | ] 406 | 407 | [[package]] 408 | name = "paw-raw" 409 | version = "1.0.0" 410 | source = "registry+https://github.com/rust-lang/crates.io-index" 411 | checksum = "7f0b59668fe80c5afe998f0c0bf93322bf2cd66cafeeb80581f291716f3467f2" 412 | 413 | [[package]] 414 | name = "proc-macro-error" 415 | version = "1.0.4" 416 | source = "registry+https://github.com/rust-lang/crates.io-index" 417 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 418 | dependencies = [ 419 | "proc-macro-error-attr", 420 | "proc-macro2", 421 | "quote", 422 | "syn 1.0.109", 423 | "version_check", 424 | ] 425 | 426 | [[package]] 427 | name = "proc-macro-error-attr" 428 | version = "1.0.4" 429 | source = "registry+https://github.com/rust-lang/crates.io-index" 430 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 431 | dependencies = [ 432 | "proc-macro2", 433 | "quote", 434 | "version_check", 435 | ] 436 | 437 | [[package]] 438 | name = "proc-macro2" 439 | version = "1.0.93" 440 | source = "registry+https://github.com/rust-lang/crates.io-index" 441 | checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" 442 | dependencies = [ 443 | "unicode-ident", 444 | ] 445 | 446 | [[package]] 447 | name = "quote" 448 | version = "1.0.38" 449 | source = "registry+https://github.com/rust-lang/crates.io-index" 450 | checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" 451 | dependencies = [ 452 | "proc-macro2", 453 | ] 454 | 455 | [[package]] 456 | name = "rayon" 457 | version = "1.10.0" 458 | source = "registry+https://github.com/rust-lang/crates.io-index" 459 | checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" 460 | dependencies = [ 461 | "either", 462 | "rayon-core", 463 | ] 464 | 465 | [[package]] 466 | name = "rayon-core" 467 | version = "1.12.1" 468 | source = "registry+https://github.com/rust-lang/crates.io-index" 469 | checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" 470 | dependencies = [ 471 | "crossbeam-deque", 472 | "crossbeam-utils", 473 | ] 474 | 475 | [[package]] 476 | name = "regex" 477 | version = "1.11.1" 478 | source = "registry+https://github.com/rust-lang/crates.io-index" 479 | checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" 480 | dependencies = [ 481 | "aho-corasick", 482 | "memchr", 483 | "regex-automata", 484 | "regex-syntax", 485 | ] 486 | 487 | [[package]] 488 | name = "regex-automata" 489 | version = "0.4.9" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" 492 | dependencies = [ 493 | "aho-corasick", 494 | "memchr", 495 | "regex-syntax", 496 | ] 497 | 498 | [[package]] 499 | name = "regex-syntax" 500 | version = "0.8.5" 501 | source = "registry+https://github.com/rust-lang/crates.io-index" 502 | checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" 503 | 504 | [[package]] 505 | name = "rustversion" 506 | version = "1.0.19" 507 | source = "registry+https://github.com/rust-lang/crates.io-index" 508 | checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" 509 | 510 | [[package]] 511 | name = "same-file" 512 | version = "1.0.6" 513 | source = "registry+https://github.com/rust-lang/crates.io-index" 514 | checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" 515 | dependencies = [ 516 | "winapi-util", 517 | ] 518 | 519 | [[package]] 520 | name = "shlex" 521 | version = "1.3.0" 522 | source = "registry+https://github.com/rust-lang/crates.io-index" 523 | checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 524 | 525 | [[package]] 526 | name = "strsim" 527 | version = "0.8.0" 528 | source = "registry+https://github.com/rust-lang/crates.io-index" 529 | checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 530 | 531 | [[package]] 532 | name = "strsim" 533 | version = "0.11.1" 534 | source = "registry+https://github.com/rust-lang/crates.io-index" 535 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 536 | 537 | [[package]] 538 | name = "structopt" 539 | version = "0.3.26" 540 | source = "registry+https://github.com/rust-lang/crates.io-index" 541 | checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" 542 | dependencies = [ 543 | "clap 2.34.0", 544 | "lazy_static", 545 | "paw", 546 | "structopt-derive", 547 | ] 548 | 549 | [[package]] 550 | name = "structopt-derive" 551 | version = "0.4.18" 552 | source = "registry+https://github.com/rust-lang/crates.io-index" 553 | checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" 554 | dependencies = [ 555 | "heck", 556 | "proc-macro-error", 557 | "proc-macro2", 558 | "quote", 559 | "syn 1.0.109", 560 | ] 561 | 562 | [[package]] 563 | name = "syn" 564 | version = "1.0.109" 565 | source = "registry+https://github.com/rust-lang/crates.io-index" 566 | checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" 567 | dependencies = [ 568 | "proc-macro2", 569 | "quote", 570 | "unicode-ident", 571 | ] 572 | 573 | [[package]] 574 | name = "syn" 575 | version = "2.0.98" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" 578 | dependencies = [ 579 | "proc-macro2", 580 | "quote", 581 | "unicode-ident", 582 | ] 583 | 584 | [[package]] 585 | name = "term" 586 | version = "1.0.1" 587 | source = "registry+https://github.com/rust-lang/crates.io-index" 588 | checksum = "a3bb6001afcea98122260987f8b7b5da969ecad46dbf0b5453702f776b491a41" 589 | dependencies = [ 590 | "home", 591 | "windows-sys 0.52.0", 592 | ] 593 | 594 | [[package]] 595 | name = "textwrap" 596 | version = "0.11.0" 597 | source = "registry+https://github.com/rust-lang/crates.io-index" 598 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 599 | dependencies = [ 600 | "unicode-width", 601 | ] 602 | 603 | [[package]] 604 | name = "thread_local" 605 | version = "1.1.8" 606 | source = "registry+https://github.com/rust-lang/crates.io-index" 607 | checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" 608 | dependencies = [ 609 | "cfg-if", 610 | "once_cell", 611 | ] 612 | 613 | [[package]] 614 | name = "unicode-ident" 615 | version = "1.0.16" 616 | source = "registry+https://github.com/rust-lang/crates.io-index" 617 | checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" 618 | 619 | [[package]] 620 | name = "unicode-segmentation" 621 | version = "1.12.0" 622 | source = "registry+https://github.com/rust-lang/crates.io-index" 623 | checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" 624 | 625 | [[package]] 626 | name = "unicode-width" 627 | version = "0.1.14" 628 | source = "registry+https://github.com/rust-lang/crates.io-index" 629 | checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" 630 | 631 | [[package]] 632 | name = "utf8parse" 633 | version = "0.2.2" 634 | source = "registry+https://github.com/rust-lang/crates.io-index" 635 | checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 636 | 637 | [[package]] 638 | name = "vec_map" 639 | version = "0.8.2" 640 | source = "registry+https://github.com/rust-lang/crates.io-index" 641 | checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" 642 | 643 | [[package]] 644 | name = "version_check" 645 | version = "0.9.5" 646 | source = "registry+https://github.com/rust-lang/crates.io-index" 647 | checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" 648 | 649 | [[package]] 650 | name = "walkdir" 651 | version = "2.5.0" 652 | source = "registry+https://github.com/rust-lang/crates.io-index" 653 | checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" 654 | dependencies = [ 655 | "same-file", 656 | "winapi-util", 657 | ] 658 | 659 | [[package]] 660 | name = "wasm-bindgen" 661 | version = "0.2.100" 662 | source = "registry+https://github.com/rust-lang/crates.io-index" 663 | checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" 664 | dependencies = [ 665 | "cfg-if", 666 | "once_cell", 667 | "rustversion", 668 | "wasm-bindgen-macro", 669 | ] 670 | 671 | [[package]] 672 | name = "wasm-bindgen-backend" 673 | version = "0.2.100" 674 | source = "registry+https://github.com/rust-lang/crates.io-index" 675 | checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" 676 | dependencies = [ 677 | "bumpalo", 678 | "log", 679 | "proc-macro2", 680 | "quote", 681 | "syn 2.0.98", 682 | "wasm-bindgen-shared", 683 | ] 684 | 685 | [[package]] 686 | name = "wasm-bindgen-macro" 687 | version = "0.2.100" 688 | source = "registry+https://github.com/rust-lang/crates.io-index" 689 | checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" 690 | dependencies = [ 691 | "quote", 692 | "wasm-bindgen-macro-support", 693 | ] 694 | 695 | [[package]] 696 | name = "wasm-bindgen-macro-support" 697 | version = "0.2.100" 698 | source = "registry+https://github.com/rust-lang/crates.io-index" 699 | checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" 700 | dependencies = [ 701 | "proc-macro2", 702 | "quote", 703 | "syn 2.0.98", 704 | "wasm-bindgen-backend", 705 | "wasm-bindgen-shared", 706 | ] 707 | 708 | [[package]] 709 | name = "wasm-bindgen-shared" 710 | version = "0.2.100" 711 | source = "registry+https://github.com/rust-lang/crates.io-index" 712 | checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" 713 | dependencies = [ 714 | "unicode-ident", 715 | ] 716 | 717 | [[package]] 718 | name = "winapi" 719 | version = "0.3.9" 720 | source = "registry+https://github.com/rust-lang/crates.io-index" 721 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 722 | dependencies = [ 723 | "winapi-i686-pc-windows-gnu", 724 | "winapi-x86_64-pc-windows-gnu", 725 | ] 726 | 727 | [[package]] 728 | name = "winapi-i686-pc-windows-gnu" 729 | version = "0.4.0" 730 | source = "registry+https://github.com/rust-lang/crates.io-index" 731 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 732 | 733 | [[package]] 734 | name = "winapi-util" 735 | version = "0.1.9" 736 | source = "registry+https://github.com/rust-lang/crates.io-index" 737 | checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" 738 | dependencies = [ 739 | "windows-sys 0.59.0", 740 | ] 741 | 742 | [[package]] 743 | name = "winapi-x86_64-pc-windows-gnu" 744 | version = "0.4.0" 745 | source = "registry+https://github.com/rust-lang/crates.io-index" 746 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 747 | 748 | [[package]] 749 | name = "windows-core" 750 | version = "0.52.0" 751 | source = "registry+https://github.com/rust-lang/crates.io-index" 752 | checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" 753 | dependencies = [ 754 | "windows-targets", 755 | ] 756 | 757 | [[package]] 758 | name = "windows-sys" 759 | version = "0.52.0" 760 | source = "registry+https://github.com/rust-lang/crates.io-index" 761 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 762 | dependencies = [ 763 | "windows-targets", 764 | ] 765 | 766 | [[package]] 767 | name = "windows-sys" 768 | version = "0.59.0" 769 | source = "registry+https://github.com/rust-lang/crates.io-index" 770 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 771 | dependencies = [ 772 | "windows-targets", 773 | ] 774 | 775 | [[package]] 776 | name = "windows-targets" 777 | version = "0.52.6" 778 | source = "registry+https://github.com/rust-lang/crates.io-index" 779 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 780 | dependencies = [ 781 | "windows_aarch64_gnullvm", 782 | "windows_aarch64_msvc", 783 | "windows_i686_gnu", 784 | "windows_i686_gnullvm", 785 | "windows_i686_msvc", 786 | "windows_x86_64_gnu", 787 | "windows_x86_64_gnullvm", 788 | "windows_x86_64_msvc", 789 | ] 790 | 791 | [[package]] 792 | name = "windows_aarch64_gnullvm" 793 | version = "0.52.6" 794 | source = "registry+https://github.com/rust-lang/crates.io-index" 795 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 796 | 797 | [[package]] 798 | name = "windows_aarch64_msvc" 799 | version = "0.52.6" 800 | source = "registry+https://github.com/rust-lang/crates.io-index" 801 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 802 | 803 | [[package]] 804 | name = "windows_i686_gnu" 805 | version = "0.52.6" 806 | source = "registry+https://github.com/rust-lang/crates.io-index" 807 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 808 | 809 | [[package]] 810 | name = "windows_i686_gnullvm" 811 | version = "0.52.6" 812 | source = "registry+https://github.com/rust-lang/crates.io-index" 813 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 814 | 815 | [[package]] 816 | name = "windows_i686_msvc" 817 | version = "0.52.6" 818 | source = "registry+https://github.com/rust-lang/crates.io-index" 819 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 820 | 821 | [[package]] 822 | name = "windows_x86_64_gnu" 823 | version = "0.52.6" 824 | source = "registry+https://github.com/rust-lang/crates.io-index" 825 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 826 | 827 | [[package]] 828 | name = "windows_x86_64_gnullvm" 829 | version = "0.52.6" 830 | source = "registry+https://github.com/rust-lang/crates.io-index" 831 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 832 | 833 | [[package]] 834 | name = "windows_x86_64_msvc" 835 | version = "0.52.6" 836 | source = "registry+https://github.com/rust-lang/crates.io-index" 837 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 838 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marks" 3 | version = "0.1.0" 4 | authors = ["Isa Mert Gurbuz "] 5 | description = "A simple and /hopefully/ fast semantic search tool for org/markdown files. WIP." 6 | edition = "2021" 7 | repository = "https://github.com/isamert/marks" 8 | license-file = "LICENSE" 9 | keywords = ["org-mode", "markdown", "search", "command-line"] 10 | categories = ["command-line-utilities", "filesystem", "text-processing"] 11 | 12 | [dependencies] 13 | clap = "4.5.27" 14 | rayon = "1.10.0" 15 | regex = "1.11.1" 16 | walkdir = "2.5.0" 17 | fuzzy-matcher = "0.3" 18 | structopt = { version = "0.3", features = [ "paw" ] } 19 | term = "1.0.1" 20 | combine = "4.6.7" 21 | chrono = "0.4.39" 22 | itertools = "0.14.0" 23 | #sublime_fuzzy = "0.6" 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # marks 2 | 3 | A simple and fast search-engine like tool for org/markdown files. WIP. 4 | 5 | ## Installation 6 | 7 | Right now you need to either clone the repository and build it yourself or install it from `crates.io` using `cargo`. 8 | 9 | ### crates.io 10 | 11 | Install `cargo` through your package manager. Then: 12 | 13 | ```bash 14 | cargo install marks 15 | ``` 16 | 17 | This will install `marks` binary under `~/.cargo/bin`. 18 | 19 | ### Cloning and installing 20 | 21 | ```bash 22 | git clone https://github.com/isamert/marks.git 23 | cd marks 24 | cargo install --path . 25 | ``` 26 | 27 | This will install `marks` binary under `~/.cargo/bin`. 28 | 29 | ## Usage 30 | 31 | `marks` is pretty intuitive, it's similar to Google. Observe the following query: 32 | 33 | ``` 34 | marks 'marks can "search" `(org|markdown)` files -folders' 35 | ``` 36 | 37 | This query requires 38 | 39 | - the word `search` to be either in the title hierarchy or in the line. 40 | - regex `(org|markdown)` to match either in the title hierarchy or in the line. 41 | - the word `folders` not to be present in the title hierarchy or the line itself. 42 | 43 | Rest of the characters are matched in fuzzy fashion. Output is similar to how grep outputs the results with only difference being title hierarchy is also added to results: `filename:line-no:title/hierarchy/here:matched-line-contents`. This command will search for all the markdown and org-mode files under given path. This is configurable. 44 | 45 | You can always do `marks --help` to get more detailed information. 46 | -------------------------------------------------------------------------------- /interactive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | INITIAL_QUERY="" 3 | RG_PREFIX="marks --no-markdown --path ~/ --query " 4 | FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \ 5 | fzf --bind "change:reload:$RG_PREFIX {q} || true" \ 6 | --ansi --phony --query "$INITIAL_QUERY" \ 7 | --layout=reverse \ 8 | --preview 'CURRLINE=$(echo {} | cut -d: -f2); bat --style=numbers --color=always --highlight-line $CURRLINE --line-range $CURRLINE: `echo {} | cut -d: -f1`' 9 | -------------------------------------------------------------------------------- /src/args.rs: -------------------------------------------------------------------------------- 1 | use std::{error::Error, path::PathBuf}; 2 | use combine::Parser; 3 | use structopt::StructOpt; 4 | 5 | use crate::{org::{datetime::{OrgDatePlan, OrgDateTime}, header::{OrgPriority, OrgTodo}}, parsers, query::Query}; 6 | 7 | #[derive(Debug, StructOpt)] 8 | #[structopt(name = "marks")] 9 | /// A search-engine like search tool for markdown and org-mode files. 10 | pub struct Args { 11 | /// Activate debug mode 12 | #[structopt(short, long)] 13 | pub debug: bool, 14 | 15 | /// How many results do you want? 16 | #[structopt(short, long)] 17 | pub count: Option, 18 | 19 | /// TODO states. 20 | #[structopt(long, parse(try_from_str = parse_todos))] 21 | pub todo: Vec, 22 | 23 | /// List of priorities. Note that items without priorites will not match if you use this option. 24 | #[structopt(long, parse(try_from_str = parse_priority))] 25 | pub priority: Vec, 26 | 27 | /// Maximum priority. 28 | #[structopt(long, parse(try_from_str = parse_priority))] 29 | pub priority_lt: Option, 30 | 31 | /// Minimum priority. 32 | #[structopt(long, parse(try_from_str = parse_priority))] 33 | pub priority_gt: Option, 34 | 35 | /// Scheduled date. 36 | #[structopt(long, parse(try_from_str = parse_org_scheduled))] 37 | pub scheduled_at: Option, 38 | 39 | /// Scheduled before. 40 | #[structopt(long, parse(try_from_str = parse_org_scheduled))] 41 | pub scheduled_before: Option, 42 | 43 | /// Scheduled after. 44 | #[structopt(long, parse(try_from_str = parse_org_scheduled))] 45 | pub scheduled_after: Option, 46 | 47 | /// List of tags that headers should contain. Headers inherit parents tags. 48 | #[structopt(long)] 49 | pub tagged: Vec, 50 | 51 | /// List of key=value pairs. If given, headers should contain given property in their property list. 52 | #[structopt(long, parse(try_from_str = parse_props))] 53 | pub prop: Vec<(String, String)>, 54 | 55 | /// Print only matching headers. 56 | /// This does not change anything in matching algorithm, only hides the content from the results. 57 | #[structopt(long)] 58 | pub only_headers: bool, 59 | 60 | /// List of extensions for org files. 61 | #[structopt(short, long, default_value = "org")] 62 | pub org_extension: Vec, 63 | 64 | /// List of extensions for org files. 65 | #[structopt(short, long, default_value = "md")] 66 | pub md_extension: Vec, 67 | 68 | /// Don't search for org files. 69 | #[structopt(long)] 70 | pub no_org: bool, 71 | 72 | /// Don't search for markdown files. 73 | #[structopt(long)] 74 | pub no_markdown: bool, 75 | 76 | /// Whether to search in files too. 77 | #[structopt(long)] 78 | pub search_filename: bool, 79 | 80 | /// Don't use colors for the output. 81 | #[structopt(long)] 82 | pub no_color: bool, 83 | 84 | /// Print a null byte after file name. 85 | #[structopt(long)] 86 | pub null: bool, 87 | 88 | /// Don't include headers to output. 89 | #[structopt(long)] 90 | pub no_headers: bool, 91 | 92 | /// A seperator to insert between headers while outputting. 93 | #[structopt(long, default_value = "/")] 94 | pub header_seperator: String, 95 | 96 | /// List folder names to blacklist 97 | #[structopt(long)] 98 | pub blacklist_folder: Vec, 99 | 100 | /// The query. 101 | /// 102 | /// An example query may look like this: 103 | /// 104 | /// '"this" is a `(test|trial)` query -badword' 105 | /// 106 | /// This query requires 107 | /// 108 | /// - the word "this" to be either in the title hierarchy or in the line. 109 | /// - regex "(test|trial)" to either in the title hierarchy or in the line. 110 | /// - "badword" to be not in the title hierarchy or the line itself. 111 | /// 112 | /// Rest of the characters are matched in fuzzy fashion. 113 | #[structopt(parse(try_from_str = parse_query), required=true, verbatim_doc_comment)] 114 | pub query: Query, 115 | 116 | /// Where to search for. 117 | #[structopt(env = "PWD", parse(try_from_str = parse_path))] 118 | pub path: PathBuf, 119 | } 120 | 121 | fn parse_props<'a>(s: &'a str) -> Result<(String, String), String> { 122 | let pos = s 123 | .find('=') 124 | .ok_or_else(|| format!("invalid PROP=value: no `=` found in `{}`", s))?; 125 | Ok((s[..pos].to_string(), s[pos + 1..].to_string())) 126 | } 127 | 128 | fn parse_query<'a>(s: &'a str) -> Result { 129 | Query::new(s) 130 | } 131 | 132 | fn parse_path<'a>(s: &'a str) -> Result { 133 | PathBuf::from(s).canonicalize() 134 | } 135 | 136 | fn parse_todos<'a>(s: &'a str) -> Result { 137 | Ok(match s.to_uppercase().as_ref() { 138 | "TODO" => OrgTodo::TODO, 139 | "DONE" => OrgTodo::DONE, 140 | x => OrgTodo::Other(x.into()) 141 | }) 142 | } 143 | 144 | fn parse_priority<'a>(s: &'a str) -> Result { 145 | Ok(OrgPriority(s.into())) 146 | } 147 | 148 | fn parse_org_date_time<'a>(s: &'a str, date_plan: OrgDatePlan) -> Result { 149 | parsers::date_time_range().parse(s).map(|(dt, _)| OrgDateTime { 150 | date_start: dt.0, 151 | date_end: dt.1, 152 | date_plan, 153 | ..Default::default() 154 | }) 155 | } 156 | 157 | fn parse_org_scheduled<'a>(s: &'a str) -> Result { 158 | parse_org_date_time(s, OrgDatePlan::Scheduled) 159 | } 160 | -------------------------------------------------------------------------------- /src/extensions.rs: -------------------------------------------------------------------------------- 1 | pub trait StartsWithIgnoreCase { 2 | fn starts_with_i(&self, pre: &str) -> bool; 3 | } 4 | 5 | impl StartsWithIgnoreCase for String { 6 | fn starts_with_i(&self, other: &str) -> bool { 7 | self.get(..other.len()) 8 | .map(|x| x.eq_ignore_ascii_case(other)) 9 | .unwrap_or(false) 10 | } 11 | } 12 | 13 | impl StartsWithIgnoreCase for &str { 14 | fn starts_with_i(&self, other: &str) -> bool { 15 | self.get(..other.len()) 16 | .map(|x| x.eq_ignore_ascii_case(other)) 17 | .unwrap_or(false) 18 | } 19 | } 20 | 21 | #[test] 22 | fn test_starts_with_i() { 23 | assert!("HuEhuUehEheUeIiIAAAA".starts_with_i("huehuueheheueiii")); 24 | assert!(!"xdxdxd".starts_with_i("huehuueheheueiii")); 25 | } 26 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod org; 2 | pub mod extensions; 3 | pub mod parsers; 4 | pub mod query; 5 | pub mod utils; 6 | pub mod result; 7 | pub mod args; 8 | pub mod marks; 9 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use itertools::Itertools; 2 | use rayon::prelude::*; 3 | use structopt::StructOpt; 4 | use std::io; 5 | 6 | use marks::args::Args; 7 | use marks::marks::Marks; // TODO: what 8 | 9 | fn main() -> Result<(), io::Error> { 10 | let args = Args::from_args(); 11 | let app = Marks::new(&args); 12 | 13 | if args.debug { 14 | println!("{:#?}", app.args); 15 | } 16 | 17 | let mut results = app 18 | .find_files() 19 | .collect::>() 20 | .par_iter() 21 | .filter_map(|f| app.search_file(&f)) 22 | .flatten() 23 | .collect::>(); 24 | 25 | results.sort_by(|a, b| b.score.partial_cmp(&a.score).unwrap()); 26 | 27 | let mut iter: Box> = Box::new(results.iter_mut()); 28 | 29 | if args.only_headers { 30 | iter = Box::new( 31 | iter 32 | .unique_by(|x| format!("{}:{}", x.file_path, x.headers.last().map_or(0, |x| x.line))) 33 | .map(|x| { x.is_header = true; x }) 34 | ); 35 | } 36 | 37 | if let Some(count) = args.count { 38 | iter = Box::new( 39 | iter.take(count) 40 | ); 41 | } 42 | 43 | iter.for_each(|x| x.print()); 44 | 45 | Ok(()) 46 | } 47 | -------------------------------------------------------------------------------- /src/marks.rs: -------------------------------------------------------------------------------- 1 | use combine::Parser; 2 | use fuzzy_matcher::skim::SkimMatcherV2; 3 | use fuzzy_matcher::FuzzyMatcher; 4 | use std::collections::HashMap; 5 | use std::fs::File; 6 | use std::io::{BufRead, BufReader}; 7 | use std::iter::Peekable; 8 | use walkdir::DirEntry; 9 | use walkdir::WalkDir; 10 | 11 | use crate::args::Args; 12 | use crate::extensions::StartsWithIgnoreCase; 13 | use crate::org::datetime::OrgDateTime; 14 | use crate::org::header::OrgHeader; 15 | use crate::parsers; 16 | use crate::result::SearchResult; 17 | use crate::utils::file_utils; 18 | 19 | pub struct Marks<'a> { 20 | pub args: &'a Args, 21 | pub matcher: SkimMatcherV2, 22 | } 23 | 24 | #[derive(Debug, Clone)] 25 | pub enum DocType { 26 | Markdown, 27 | OrgMode, 28 | } 29 | 30 | impl<'a> Marks<'a> { 31 | pub fn new(args: &'a Args) -> Marks<'a> { 32 | // TODO: parametrize this 33 | let matcher = SkimMatcherV2::default(); 34 | 35 | Marks { args, matcher } 36 | } 37 | 38 | pub fn find_files(&'a self) -> impl Iterator + 'a { 39 | WalkDir::new(&self.args.path) 40 | .into_iter() 41 | .filter_entry(move |e| !file_utils::is_hidden(e) && !self.is_file_blacklisted(e)) 42 | .filter_map(|e| e.ok()) 43 | .filter_map(move |e| { 44 | if e.file_type().is_file() { 45 | if (!self.args.no_org && self.is_org_file(&e)) 46 | || (!self.args.no_markdown && self.is_md_file(&e)) 47 | { 48 | return Some(e); 49 | } 50 | } 51 | 52 | return None; 53 | }) 54 | } 55 | 56 | // TODO: refactor/divide into smaller functions 57 | pub fn search_file(&self, file: &DirEntry) -> Option> { 58 | let filename = file.file_name().to_str()?; 59 | let doc_type = self.get_doc_type(&file); 60 | 61 | let reader = BufReader::new(File::open(file.path()).ok()?); 62 | let mut results = vec![]; 63 | 64 | let mut headers: Vec = vec![]; 65 | let mut last_depth = 0; 66 | let mut skip_section = false; 67 | 68 | let mut iter = reader.lines().filter_map(|x| x.ok()).enumerate().peekable(); 69 | while let Some((index, line)) = iter.next() { 70 | let header_info = self.parse_header(&mut iter, &doc_type, &line, index); 71 | let is_header = header_info.is_some(); 72 | 73 | if let Some(header) = header_info { 74 | let depth = header.depth; 75 | 76 | if depth > last_depth { 77 | headers.push(header); 78 | } else if last_depth == depth { 79 | let lastn = headers.len() - 1; 80 | headers[lastn] = header; 81 | } else { 82 | headers.truncate(depth); 83 | 84 | // (depth - 1) will not work because header hiearchy may go like this: 85 | // * *** 86 | let curr_len = headers.len(); 87 | headers[curr_len - 1] = header; 88 | } 89 | last_depth = depth; 90 | 91 | // Check if any of the headers in the hierarchy contains the given tags 92 | // or the given props. Skip the check if we already found match in any of the parent headers. 93 | if !(!skip_section && depth > last_depth) { 94 | let matches_tags = self 95 | .args 96 | .tagged 97 | .iter() 98 | .all(|x| headers.iter().any(|header| header.tags.contains(x))); 99 | 100 | let matches_props = self.args.prop.iter().all(|(key, val)| { 101 | headers.iter().any(|header| { 102 | header 103 | .properties 104 | .get(key) 105 | .map(|header_val| header_val == val) 106 | .unwrap_or(false) 107 | }) 108 | }); 109 | 110 | skip_section = !(matches_tags && matches_props) 111 | } 112 | 113 | if !skip_section { 114 | let curr_header = headers.last().unwrap(); 115 | if !self.args.todo.is_empty() { 116 | let has_todo = self 117 | .args 118 | .todo 119 | .iter() 120 | .any(|x| curr_header.todo.as_ref().map_or(false, |y| y == x)); 121 | skip_section = skip_section || !has_todo; 122 | } 123 | 124 | if !self.args.priority.is_empty() { 125 | let is_right_priority = self 126 | .args 127 | .priority 128 | .iter() 129 | .any(|x| curr_header.priority.as_ref().map_or(false, |y| x == y)); 130 | 131 | skip_section = skip_section || !is_right_priority; 132 | } 133 | 134 | if let Some(priority) = &self.args.priority_lt { 135 | let is_lt_than = curr_header 136 | .priority 137 | .as_ref() 138 | .map_or(false, |x| x < priority); 139 | skip_section = skip_section || !is_lt_than; 140 | } 141 | 142 | if let Some(priority) = &self.args.priority_gt { 143 | let is_gt_than = curr_header 144 | .priority 145 | .as_ref() 146 | .map_or(false, |x| x > priority); 147 | skip_section = skip_section || !is_gt_than; 148 | } 149 | 150 | if let Some(schedule) = &self.args.scheduled_at { 151 | //println!("{:?}", curr_header.datetime); 152 | skip_section = skip_section || !curr_header 153 | .datetime 154 | .as_ref() 155 | .map_or(false, |datetime| datetime.compare_with(schedule, PartialEq::eq, PartialEq::eq)); 156 | } 157 | } 158 | } 159 | 160 | // Skip 0-level if are looking for props or tags 161 | // FIXME: For level-0 we might want to parse #+TITLE #+FILETAGS etc. to make the check 162 | // but this requires these constructs to be found at the top of the file, otherwise 163 | // they'll become pointless. 164 | if last_depth == 0 165 | && (!self.args.tagged.is_empty() 166 | || !self.args.prop.is_empty() 167 | || !self.args.priority.is_empty() 168 | || self.args.priority_lt.is_some() 169 | || self.args.priority_gt.is_some() 170 | || self.args.scheduled_at.is_some()) 171 | { 172 | skip_section = true; 173 | } 174 | 175 | if skip_section { 176 | continue; 177 | } 178 | 179 | // TODO: Maybe don't do this every loop? 180 | let full: String = { 181 | let mut result = headers 182 | .iter() 183 | .map(|x| x.content.to_owned()) 184 | .collect::>() 185 | .join(" / "); 186 | 187 | if !is_header { 188 | result.push_str(&line); 189 | } 190 | 191 | if self.args.search_filename { 192 | result.push_str(&filename); 193 | } 194 | 195 | result 196 | }; 197 | 198 | // Check regexes 199 | if !self.args.query.regexes.iter().all(|x| x.is_match(&full)) 200 | || !self.args.query.musts.iter().all(|x| full.contains(x)) 201 | || self.args.query.nones.iter().any(|x| full.contains(x)) 202 | { 203 | continue; 204 | } 205 | 206 | // Fuzzy match 207 | let points = self 208 | .args 209 | .query 210 | .rest 211 | .iter() 212 | .filter_map(|q| self.matcher.fuzzy_match(&full, &q)) 213 | .collect::>(); 214 | if points.len() > 0 || self.args.query.rest.len() == 0 { 215 | results.push(SearchResult { 216 | line: index + 1, 217 | file_path: file.path().to_str()?.to_string(), 218 | score: points.iter().sum::(), 219 | headers: headers.clone(), 220 | content: line, 221 | args: self.args, 222 | is_header, 223 | }); 224 | } 225 | } 226 | 227 | return Some(results); 228 | } 229 | 230 | fn is_file_blacklisted(&'a self, entry: &DirEntry) -> bool { 231 | entry 232 | .file_name() 233 | .to_str() 234 | .map(|s| self.args.blacklist_folder.contains(&s.to_string())) 235 | .unwrap_or(false) 236 | } 237 | 238 | fn is_org_file(&'a self, e: &DirEntry) -> bool { 239 | match e.path().extension().map(|x| x.to_str()).flatten() { 240 | Some(x) => self.args.org_extension.iter().any(|y| x == y), 241 | None => false, 242 | } 243 | } 244 | 245 | fn is_md_file(&'a self, e: &DirEntry) -> bool { 246 | match e.path().extension().map(|x| x.to_str()).flatten() { 247 | Some(x) => self.args.md_extension.iter().any(|y| x == y), 248 | None => false, 249 | } 250 | } 251 | 252 | fn get_doc_type(&self, file: &DirEntry) -> DocType { 253 | if self.is_md_file(file) { 254 | return DocType::Markdown; 255 | } else { 256 | return DocType::OrgMode; 257 | } 258 | } 259 | 260 | fn parse_header( 261 | &self, 262 | iter: &mut Peekable, 263 | typ: &DocType, 264 | line: &str, 265 | idx: usize, 266 | ) -> Option 267 | where 268 | I: Iterator, 269 | { 270 | let x = match typ { 271 | DocType::Markdown => '#', 272 | DocType::OrgMode => '*', 273 | }; 274 | 275 | let mut chars = line.chars().into_iter(); 276 | if chars.next() != Some(x) { 277 | return None; 278 | } 279 | 280 | let mut depth: usize = 1; 281 | for chr in &mut chars { 282 | if chr == x { 283 | depth += 1; 284 | continue; 285 | } else if chr == ' ' { 286 | break; 287 | } else { 288 | return None; 289 | } 290 | } 291 | 292 | // TODO: it might be good if user does not search for these, simply don't parse them 293 | // ex. if --prop does not exist in args, simply skip parse_org_props() call etc. 294 | let (tags, rest) = self.parse_org_tags(&mut chars); 295 | let ((todo, priority), content) = parsers::org_todo().parse(rest.as_str()).ok()?; 296 | // FIXME: properties may come after datetime or vice versa. Not really sure tho 297 | let datetime = self.parse_org_date_time(iter); 298 | let properties = self.parse_org_props(iter); 299 | 300 | Some(OrgHeader { 301 | depth, 302 | content: content.into(), 303 | properties, 304 | tags, 305 | datetime, 306 | line: idx, 307 | args: self.args, 308 | todo, 309 | priority, 310 | }) 311 | } 312 | 313 | fn parse_org_date_time(&self, iter: &mut Peekable) -> Option 314 | where 315 | I: Iterator, 316 | { 317 | // Only ISO 8601 dates are supported 318 | // TODO: handle plain timestamps after headers 319 | let has_schedule = iter 320 | .peek() 321 | .map(|(_, x)| x.starts_with_i("DEADLINE:") || x.starts_with_i("SCHEDULED:")) 322 | .unwrap_or(false); 323 | 324 | if has_schedule { 325 | let (_, line_date) = iter.next().unwrap(); 326 | let result: Result<(OrgDateTime, &str), _> = 327 | parsers::org_date_time().parse(line_date.as_str()); 328 | result.ok().map(|x| x.0) 329 | } else { 330 | None 331 | } 332 | } 333 | 334 | /// Parse the tags from given line and return the tags along with the header that is stripped from the tags and whitespace. 335 | fn parse_org_tags(&self, chars: &mut I) -> (Vec, String) 336 | where 337 | I: DoubleEndedIterator, 338 | { 339 | let mut rev_chars = chars.rev().peekable(); 340 | let has_tags = rev_chars.peek().map(|x| *x == ':').unwrap_or(false); 341 | let rev_header = rev_chars.collect::(); 342 | 343 | if has_tags { 344 | let result: Result<(Vec, &str), _> = 345 | parsers::org_tags().parse(rev_header.as_str()); 346 | if let Ok((tags, rest)) = result { 347 | (tags, rest.chars().rev().collect::()) 348 | } else { 349 | (vec![], rev_header.chars().rev().collect()) 350 | } 351 | } else { 352 | (vec![], rev_header.chars().rev().collect()) 353 | } 354 | } 355 | 356 | fn parse_org_props(&self, iter: &mut Peekable) -> HashMap 357 | where 358 | I: Iterator, 359 | { 360 | let has_props = iter 361 | .peek() 362 | .map(|(_, x)| x.starts_with_i(":PROPERTIES:")) 363 | .unwrap_or(false); 364 | let mut props: HashMap = HashMap::new(); 365 | 366 | if has_props { 367 | iter.next(); // Consume :PROPERTIES: 368 | 369 | while let Some((_, prop)) = iter.next() { 370 | if prop.starts_with_i(":END:") { 371 | return props; 372 | } else { 373 | let result: Result<((String, String), &str), _> = 374 | parsers::org_property().parse(&prop); 375 | if let Ok(((key, val), _)) = result { 376 | props.insert(key, val); 377 | } else { 378 | // Probably :PROPERTIES: block does not have :END: 379 | // (I just assumed this to not to consume whole file, it might just be a bad property line) 380 | // so just return what we just have found so far 381 | return props; 382 | } 383 | } 384 | } 385 | } 386 | 387 | props 388 | } 389 | } 390 | -------------------------------------------------------------------------------- /src/org/datetime.rs: -------------------------------------------------------------------------------- 1 | use chrono::prelude::*; 2 | 3 | #[derive(Debug, Eq, PartialEq, Clone)] 4 | pub enum OrgDatePlan { 5 | /// SCHEDULED dates 6 | Scheduled, 7 | /// DEADLINE dates 8 | Deadline, 9 | /// Just plain dates, no DEADLINE or SCHEDULED prefix 10 | Plain, 11 | } 12 | 13 | /// Some possible formats: 14 | /// <2003-09-16 Tue> 15 | /// <2003-09-16 Tue 12:00-12:30> 16 | /// <2003-09-16 Tue 12:00>--<2003-09-19 Tue 14:30> 17 | #[derive(Debug, PartialEq, Eq, Clone)] 18 | pub struct OrgDateTime { 19 | /// <...> is for active dates, [...] is for passive dates. 20 | pub is_active: bool, 21 | /// Is it SCHEDULED, DEADLINE or just plain date? 22 | pub date_plan: OrgDatePlan, 23 | /// First date found in the org datetime. 24 | pub date_start: DateTime, 25 | /// Second date found in the org datetime. Following formats has the second date: 26 | /// <...>--<...> 27 | /// <... HH:MM-HH-MM>. 28 | pub date_end: Option>, 29 | /// Invertal. Not quite useful at this point. 30 | /// https://orgmode.org/manual/Repeated-tasks.html 31 | pub invertal: Option, 32 | } 33 | 34 | impl Default for OrgDateTime { 35 | fn default() -> Self { 36 | OrgDateTime { 37 | is_active: true, 38 | date_plan: OrgDatePlan::Plain, 39 | date_start: Utc::now(), 40 | date_end: None, 41 | invertal: None, 42 | } 43 | } 44 | } 45 | 46 | impl OrgDateTime { 47 | pub fn compare_with(&self, other: &Self, compare1: fn(&DateTime, &DateTime) -> bool, compare2: fn(&Date, &Date) -> bool) -> bool { 48 | let compare_only_dates = (other.date_start.hour(), other.date_start.minute(), other.date_start.second()) == (0,0,0); 49 | let is_same_plan = self.date_plan == other.date_plan; 50 | 51 | is_same_plan && if compare_only_dates { 52 | compare2(&self.date_start.date(), &other.date_start.date()) 53 | } else { 54 | compare1(&self.date_start, &other.date_start) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/org/header.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use crate::args::Args; 4 | use crate::org::datetime::OrgDateTime; 5 | 6 | #[derive(Debug, Eq, PartialEq, Clone)] 7 | pub struct OrgPriority(pub String); 8 | 9 | impl PartialOrd for OrgPriority { 10 | fn partial_cmp(&self, other: &Self) -> Option { 11 | if self.0.chars().all(|x| x.is_alphabetic()) { // A > B 12 | other.0.partial_cmp(&self.0) 13 | } else if self.0.chars().all(|x| x.is_digit(10)) { // 2 > 1 14 | self.0.parse::().unwrap_or(0).partial_cmp(&other.0.parse::().unwrap_or(0)) 15 | } else { 16 | self.0.partial_cmp(&other.0) 17 | } 18 | } 19 | } 20 | 21 | #[derive(Debug, Eq, PartialEq, Clone, Hash)] 22 | pub enum OrgTodo { 23 | TODO, 24 | DONE, 25 | Other(String), 26 | } 27 | 28 | #[derive(Debug, Clone)] 29 | pub struct OrgHeader<'a> { 30 | /// Args 31 | pub args: &'a Args, 32 | /// On which line is the header found. 33 | pub line: usize, 34 | /// This usually means the count of # (for md) or * (for org) at the beginning of the header line. 35 | pub depth: usize, 36 | /// The header itself, stripped from tags or other annotations. 37 | pub content: String, 38 | /// Tags found in the header. Means nothing for markdown headers. 39 | pub tags: Vec, 40 | /// Properties found in :PROPERTIES: block of an org header. Means nothing for markdown headers. 41 | pub properties: HashMap, 42 | /// SCHEDULED/DEADLINE status of the header. 43 | pub datetime: Option, 44 | /// TODO state 45 | pub todo: Option, 46 | /// The priority, like [#...], ... being anything 47 | pub priority: Option, 48 | } 49 | 50 | #[test] 51 | fn test_priority_ordering() { 52 | assert!(OrgPriority("A".into()) > OrgPriority("B".into())); 53 | assert!(OrgPriority("3".into()) > OrgPriority("2".into())); 54 | assert!(OrgPriority("15".into()) > OrgPriority("13".into())); 55 | assert!(OrgPriority("A".into()) == OrgPriority("A".into())); 56 | } 57 | -------------------------------------------------------------------------------- /src/org/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod datetime; 2 | pub mod header; 3 | -------------------------------------------------------------------------------- /src/parsers.rs: -------------------------------------------------------------------------------- 1 | use chrono::prelude::*; 2 | use combine::error::ParseError; 3 | use combine::parser::char::*; 4 | use combine::Stream; 5 | use combine::*; 6 | 7 | use crate::org::datetime::{OrgDatePlan, OrgDateTime}; 8 | use crate::org::header::*; 9 | 10 | /// Parse `HH:MM`. 11 | pub fn hour() -> impl Parser 12 | where 13 | Input: Stream, 14 | Input::Error: ParseError, 15 | { 16 | ( 17 | count_min_max(2, 2, digit()).map(|x: String| x.parse::().unwrap()), 18 | token(':'), 19 | count_min_max(2, 2, digit()).map(|x: String| x.parse::().unwrap()), 20 | ) 21 | .map(|(h, _, m)| (h, m)) 22 | } 23 | 24 | /// Parse `HH:MM-HH:MM`. Second part is optional. 25 | pub fn hour_range() -> impl Parser)> 26 | where 27 | Input: Stream, 28 | Input::Error: ParseError, 29 | { 30 | (hour(), optional(token('-').and(hour()))).map(|(x, y)| (x, y.map(|(_, a)| a))) 31 | } 32 | 33 | 34 | /// Parse `HH:MM-HH:MM`. Second part is optional. 35 | pub fn date_time_range() -> impl Parser, Option>)> 36 | where 37 | Input: Stream, 38 | Input::Error: ParseError, 39 | { 40 | ( 41 | count(4, digit()).map(|x: String| x.parse::().unwrap()), 42 | token('-'), 43 | count(2, digit()).map(|x: String| x.parse::().unwrap()), 44 | token('-'), 45 | count(2, digit()).map(|x: String| x.parse::().unwrap()), 46 | spaces(), 47 | optional(count(3, letter()).map(|x: String| x)), 48 | spaces().silent(), 49 | optional(hour_range()).map(|hour| hour.unwrap_or(((0, 0), None))), 50 | ).map(|(year, _, month, _, day, _, _, _, hour)| ( 51 | Utc.ymd(year, month, day).and_hms(hour.0 .0, hour.0 .1, 0), 52 | hour.1.map(|end| Utc.ymd(year, month, day).and_hms(end.0, end.1, 0)) 53 | )) 54 | } 55 | 56 | 57 | pub fn org_date_time() -> impl Parser 58 | where 59 | Input: Stream, 60 | Input::Error: ParseError, 61 | { 62 | let invertal_parser = many1(satisfy(|x| x != '>' && x != ']')); 63 | 64 | ( 65 | spaces().silent(), 66 | many1(letter()).map(|x: String| match x.as_str() { 67 | "DEADLINE" => OrgDatePlan::Deadline, 68 | "SCHEDULED" => OrgDatePlan::Scheduled, 69 | _ => OrgDatePlan::Plain, // FIXME: this is wrong, it should not happen 70 | }), 71 | token(':'), 72 | spaces().silent(), 73 | choice((token('<'), token('['))).map(|c| c == '<'), // < means active, [ means inactive 74 | date_time_range(), 75 | spaces().silent(), 76 | optional(invertal_parser), 77 | choice((token(']'), token('>'))), 78 | ) 79 | .map(|(_, date_plan, _, _, is_active, datetime, _, invertal, _,)| OrgDateTime { 80 | is_active, 81 | date_plan, 82 | date_start: datetime.0, 83 | date_end: datetime.1, 84 | invertal, 85 | }) 86 | } 87 | 88 | pub fn org_tags() -> impl Parser> 89 | where 90 | Input: Stream, 91 | Input::Error: ParseError, 92 | { 93 | ( 94 | spaces().silent(), 95 | token(':'), 96 | sep_end_by1(many1(alpha_num()), token(':')) 97 | .map(|xs: Vec| xs.iter().map(|x| x.chars().rev().collect()).collect()), 98 | spaces().silent(), 99 | ) 100 | .map(|(_, _, tags, _)| tags) 101 | } 102 | 103 | pub fn org_todo() -> impl Parser, Option)> 104 | where 105 | Input: Stream, 106 | Input::Error: ParseError, 107 | { 108 | let org_priority = (token('['), token('#'), many(alpha_num()), token(']')) 109 | .map(|(_, _, priority, _)| OrgPriority(priority)); 110 | 111 | ( 112 | spaces().silent(), 113 | optional(attempt(many1(upper()).and(space()).map( 114 | |(x, _): (String, _)| match x.as_str() { 115 | "TODO" => OrgTodo::TODO, 116 | "DONE" => OrgTodo::DONE, 117 | _ => OrgTodo::Other(x), 118 | }, 119 | ))), 120 | spaces().silent(), 121 | optional(attempt(org_priority)), 122 | spaces().silent(), 123 | ) 124 | .map(|(_, todo, _, priority, _)| (todo, priority)) 125 | } 126 | 127 | pub fn org_property() -> impl Parser 128 | where 129 | Input: Stream, 130 | Input::Error: ParseError, 131 | { 132 | let non_colon = satisfy(|x| x != ':'); 133 | ( 134 | between(char(':'), char(':'), many1(non_colon)), 135 | spaces().silent(), 136 | many(any()), 137 | ) 138 | .map(|(key, _, val)| (key, val)) 139 | } 140 | 141 | #[test] 142 | fn test_hour() { 143 | assert_eq!(hour().parse("13:27").unwrap().0, (13, 27)); 144 | assert_eq!(hour().parse("15:42").unwrap().0, (15, 42)); 145 | } 146 | 147 | #[test] 148 | fn test_hour_range() { 149 | assert_eq!(hour_range().parse("13:27").unwrap().0, ((13, 27), None)); 150 | assert_eq!( 151 | hour_range().parse("13:27-14:30").unwrap().0, 152 | ((13, 27), Some((14, 30))) 153 | ); 154 | assert_eq!( 155 | hour_range().parse("19:00-19:30").unwrap().0, 156 | ((19, 00), Some((19, 30))) 157 | ); 158 | } 159 | 160 | #[test] 161 | fn test_org_date_time() { 162 | assert_eq!( 163 | org_date_time() 164 | .parse("DEADLINE: <2020-12-24 Thu>") 165 | .unwrap() 166 | .0, 167 | OrgDateTime { 168 | is_active: true, 169 | date_plan: OrgDatePlan::Deadline, 170 | date_start: Utc.ymd(2020, 12, 24).and_hms(0, 0, 0), 171 | date_end: None, 172 | invertal: None, 173 | } 174 | ); 175 | 176 | assert_eq!( 177 | org_date_time() 178 | .parse("DEADLINE: <2020-12-24 Thu 13:30>") 179 | .unwrap() 180 | .0, 181 | OrgDateTime { 182 | is_active: true, 183 | date_plan: OrgDatePlan::Deadline, 184 | date_start: Utc.ymd(2020, 12, 24).and_hms(13, 30, 0), 185 | date_end: None, 186 | invertal: None, 187 | } 188 | ); 189 | 190 | assert_eq!( 191 | org_date_time() 192 | .parse("DEADLINE: [2020-12-24 Thu 13:30]") 193 | .unwrap() 194 | .0, 195 | OrgDateTime { 196 | is_active: false, 197 | date_plan: OrgDatePlan::Deadline, 198 | date_start: Utc.ymd(2020, 12, 24).and_hms(13, 30, 0), 199 | date_end: None, 200 | invertal: None, 201 | } 202 | ); 203 | 204 | assert_eq!( 205 | org_date_time() 206 | .parse("DEADLINE: [2020-12-24 Thu 13:30 +1y]") 207 | .unwrap() 208 | .0, 209 | OrgDateTime { 210 | is_active: false, 211 | date_plan: OrgDatePlan::Deadline, 212 | date_start: Utc.ymd(2020, 12, 24).and_hms(13, 30, 0), 213 | date_end: None, 214 | invertal: Some("+1y".into()), 215 | } 216 | ); 217 | 218 | assert_eq!( 219 | org_date_time() 220 | .parse("DEADLINE: [2020-12-24 Thu 13:30-22:35 +1y]") 221 | .unwrap() 222 | .0, 223 | OrgDateTime { 224 | is_active: false, 225 | date_plan: OrgDatePlan::Deadline, 226 | date_start: Utc.ymd(2020, 12, 24).and_hms(13, 30, 0), 227 | date_end: Some(Utc.ymd(2020, 12, 24).and_hms(22, 35, 0)), 228 | invertal: Some("+1y".into()), 229 | } 230 | ); 231 | } 232 | 233 | #[test] 234 | fn test_org_tags() { 235 | assert_eq!( 236 | org_tags() 237 | .parse(" :tset:2tset:3tset: tser **") 238 | .unwrap(), 239 | ( 240 | vec!["test".into(), "test2".into(), "test3".into()], 241 | "tser **" 242 | ) 243 | ) 244 | } 245 | 246 | #[test] 247 | fn test_org_todo() { 248 | assert_eq!( 249 | org_todo().parse(" TODO The Ego and Its Own").unwrap(), 250 | ((Some(OrgTodo::TODO), None), "The Ego and Its Own") 251 | ); 252 | 253 | assert_eq!( 254 | org_todo().parse("DONE [#B] The German Ideology").unwrap(), 255 | ( 256 | (Some(OrgTodo::DONE), Some(OrgPriority("B".into()))), 257 | "The German Ideology" 258 | ) 259 | ); 260 | 261 | assert_eq!( 262 | org_todo().parse("PROG [#33] hehe").unwrap(), 263 | ( 264 | (Some(OrgTodo::Other("PROG".into())), Some(OrgPriority("33".into()))), 265 | "hehe" 266 | ) 267 | ); 268 | } 269 | -------------------------------------------------------------------------------- /src/query.rs: -------------------------------------------------------------------------------- 1 | use regex::Regex; 2 | 3 | use combine::parser::char::{char, spaces}; 4 | use combine::stream::easy::ParseError; 5 | use combine::{between, choice, many1, satisfy, sep_by, EasyParser, Parser}; 6 | 7 | #[derive(Debug)] 8 | pub enum QueryToken { 9 | Regex(Regex), 10 | Must(String), 11 | None(String), 12 | Plain(String), 13 | } 14 | 15 | #[derive(Debug)] 16 | pub struct Query { 17 | /// Query string that user provided. 18 | pub full: String, 19 | /// "keyword" 20 | pub musts: Vec, 21 | /// -keyword 22 | pub nones: Vec, 23 | /// `(some|regex)` 24 | pub regexes: Vec, 25 | /// full - (musts + nones + regexes). Used for fuzzy searching. 26 | pub rest: Vec, 27 | } 28 | 29 | /// Solely for testing 30 | impl PartialEq for Query { 31 | fn eq(&self, other: &Self) -> bool { 32 | self.full == other.full 33 | && self.musts == other.musts 34 | && self.nones == other.nones 35 | && self.regexes.iter().zip(other.regexes.iter()).all(|(x, y)| x.as_str() == y.as_str()) 36 | && self.rest == other.rest 37 | } 38 | } 39 | 40 | impl Eq for Query {} 41 | 42 | impl Query { 43 | pub fn new(input: &str) -> Result> { 44 | let full = input.to_string(); 45 | let mut musts: Vec = vec![]; 46 | let mut nones = vec![]; 47 | let mut regexes = vec![]; 48 | let mut rest = vec![]; 49 | 50 | let non_ws = satisfy(|x| x != ' '); 51 | let non_quote = satisfy(|x| x != '"'); 52 | let non_backtick = satisfy(|x| x != '`'); 53 | 54 | let token = choice(( 55 | between(char('"'), char('"'), many1(non_quote)).map(|x: String| QueryToken::Must(x)), 56 | between(char('`'), char('`'), many1(non_backtick)) 57 | .map(|x: String| QueryToken::Regex(Regex::new(&x).unwrap())), 58 | (char('-'), many1(non_ws)).map(|x| QueryToken::None(x.1)), 59 | many1(non_ws).map(|x| QueryToken::Plain(x)), 60 | )); 61 | let mut query = sep_by(token, spaces()); 62 | let result: Result<(Vec, &str), ParseError<&str>> = query.easy_parse(input); 63 | 64 | result?.0.into_iter().for_each(|x| match x { 65 | QueryToken::Regex(r) => regexes.push(r), 66 | QueryToken::Plain(r) => rest.push(r), 67 | QueryToken::Must(r) => musts.push(r), 68 | QueryToken::None(r) => nones.push(r), 69 | }); 70 | 71 | Ok(Query { 72 | full, 73 | musts, 74 | nones, 75 | regexes, 76 | rest, 77 | }) 78 | } 79 | } 80 | 81 | impl Default for Query { 82 | fn default() -> Self { 83 | Query { 84 | full: String::new(), 85 | musts: vec![], 86 | nones: vec![], 87 | regexes: vec![], 88 | rest: vec![], 89 | } 90 | } 91 | } 92 | 93 | #[test] 94 | fn test_parse_query() { 95 | assert_eq!(Query::new("").unwrap(), Query::default()); 96 | assert_eq!(Query::new("-badword \"stuff\" \"another stuff\" hehe `a regex`").unwrap(), Query { 97 | full: "-badword \"stuff\" \"another stuff\" hehe `a regex`".into(), 98 | musts: vec!["stuff".into(), "another stuff".into()], 99 | nones: vec!["badword".into()], 100 | rest: vec!["hehe".into()], 101 | regexes: vec![Regex::new("a regex").unwrap()], 102 | ..Default::default() 103 | }); 104 | } 105 | -------------------------------------------------------------------------------- /src/result.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use crate::{args::Args, org::header::OrgHeader}; 4 | 5 | #[derive(Debug)] 6 | pub struct SearchResult<'a> { 7 | /// Score. 8 | pub score: i64, 9 | /// Line number. 10 | pub line: usize, 11 | /// In which file? 12 | pub file_path: String, 13 | /// List of headers that this belongs to. 14 | pub headers: Vec>, 15 | /// Full line content itself. 16 | pub content: String, 17 | /// Is this a header line? 18 | pub is_header: bool, 19 | pub args: &'a Args, 20 | } 21 | 22 | // TODO: Unify printing logic into one 23 | // TODO: Print JSON? 24 | 25 | impl<'a> SearchResult<'a> { 26 | #[allow(unused_must_use)] 27 | pub fn print(&self) { 28 | if self.args.no_color { 29 | return println!("{}", self); 30 | } 31 | 32 | let mut t = term::stdout().unwrap(); 33 | t.fg(term::color::MAGENTA).unwrap(); 34 | write!(t, "{}", self.file_path).unwrap(); 35 | 36 | if self.args.null { 37 | write!(t, "\0").unwrap(); 38 | } else { 39 | t.fg(term::color::WHITE).unwrap(); 40 | write!(t, ":").unwrap(); 41 | }; 42 | 43 | t.fg(term::color::GREEN).unwrap(); 44 | write!(t, "{}", self.line).unwrap(); 45 | 46 | t.fg(term::color::WHITE).unwrap(); 47 | write!(t, ":").unwrap(); 48 | 49 | if !self.args.no_headers { 50 | let mut sep = ""; 51 | for header in self.headers.iter() { 52 | t.fg(term::color::WHITE).unwrap(); 53 | write!(t, "{}", sep).unwrap(); 54 | 55 | sep = &self.args.header_seperator; 56 | 57 | t.fg(term::color::BLUE).unwrap(); 58 | write!(t, "{}", header.content).unwrap(); 59 | } 60 | } 61 | 62 | if !self.is_header { 63 | t.fg(term::color::WHITE).unwrap(); 64 | if self.headers.len() > 0 { 65 | write!(t, ":").unwrap(); 66 | } 67 | 68 | t.reset().unwrap(); 69 | write!(t, "{}", self.content).unwrap(); 70 | } 71 | 72 | writeln!(t); 73 | } 74 | } 75 | 76 | /// Format SearchResult to print it out into 77 | impl fmt::Display for SearchResult<'_> { 78 | #[allow(unused_must_use)] 79 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 80 | let file_and_line_sep: char = if self.args.null { 81 | '\0' 82 | } else { 83 | ':' 84 | }; 85 | write!(f, "{}{}{}", &self.file_path, file_and_line_sep, &self.line); 86 | if !self.args.no_headers { 87 | let mut sep = ":"; 88 | for header in self.headers.iter() { 89 | write!(f, "{}", sep).unwrap(); 90 | sep = &self.args.header_seperator; 91 | write!(f, "{}", header.content).unwrap(); 92 | } 93 | } 94 | write!(f, ":{}", &self.content) 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/utils.rs: -------------------------------------------------------------------------------- 1 | pub mod file_utils { 2 | use walkdir::DirEntry; 3 | 4 | /// Returns if the file starts with dot (".") or not. 5 | pub fn is_hidden(entry: &DirEntry) -> bool { 6 | entry 7 | .file_name() 8 | .to_str() 9 | .map(|s| s.starts_with(".")) 10 | .unwrap_or(false) 11 | } 12 | } 13 | --------------------------------------------------------------------------------