diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-14 10:46:28 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-14 10:46:28 -0500 |
commit | be2bf751536850e7bdfbd876ef908c5d6cf00087 (patch) | |
tree | 91d426b4b9f2e763aa5f23931f5ef166b47c2393 /lib/grep.ml | |
parent | fde592dbbb97a89a498feb95f97bee674bd571e8 (diff) | |
download | stitch-be2bf751536850e7bdfbd876ef908c5d6cf00087.tar.gz stitch-be2bf751536850e7bdfbd876ef908c5d6cf00087.tar.bz2 stitch-be2bf751536850e7bdfbd876ef908c5d6cf00087.zip |
Add search and tag search
Diffstat (limited to 'lib/grep.ml')
-rw-r--r-- | lib/grep.ml | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/grep.ml b/lib/grep.ml index a6ba300..e438d0a 100644 --- a/lib/grep.ml +++ b/lib/grep.ml @@ -4,16 +4,42 @@ let execution_directory = let grep_cmd = Sys.getenv_opt "STICH_GREP_CMD" |> Option.value ~default:"ugrep" +let tag_pattern = + Sys.getenv_opt "STITCH_TAG_PATTERN" |> Option.value ~default:":[a-z_-]+:" + + +let headline_pattern = + Sys.getenv_opt "STITCH_HEADLINE_PATTERN" |> Option.value ~default:"^\\* " + + let run_print ~dir args = let open Shexp_process in let open Shexp_process.Infix in eval (chdir dir (call args |- read_all)) -let get_headlines () = - run_print - ~dir:execution_directory - [ grep_cmd; "^\\*"; "-H"; "-r"; "-n"; "--separator=|" ] +let headline_args = + [ grep_cmd; "^\\*"; "-H"; "-r"; "-n"; "--separator=|"; "--no-messages" ] + + +let get_headlines () = run_print ~dir:execution_directory headline_args + +let get_tagged_headlines tag () = + let open Shexp_process in + let open Shexp_process.Infix in + eval + (chdir + execution_directory + (call headline_args |- call [ grep_cmd; "-E"; "--no-messages"; tag ] |- read_all)) + + +let get_tags () = + let open Shexp_process in + let open Shexp_process.Infix in + eval + (chdir + execution_directory + (call headline_args |- call [ grep_cmd; "-E"; tag_pattern; "-o" ] |- read_all)) exception Not_A_Tuple of string * string |