aboutsummaryrefslogtreecommitdiff
path: root/lib/grep.ml
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/grep.ml34
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