From 89817d53ec7dbf5cff9c873afe9b7bc939dbe8c3 Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Tue, 14 May 2024 11:21:26 -0500 Subject: Add sort algorithms --- lib/grep.ml | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/grep.ml b/lib/grep.ml index e438d0a..0d79c57 100644 --- a/lib/grep.ml +++ b/lib/grep.ml @@ -12,6 +12,21 @@ let headline_pattern = Sys.getenv_opt "STITCH_HEADLINE_PATTERN" |> Option.value ~default:"^\\* " +let find_sort_modification () = + let open Shexp_process in + let open Shexp_process.Infix in + call [ "find"; "."; "-printf"; "%Ts/%f\\n" ] + |- call [ "sort"; "-n" ] + |- call [ "cut"; "-c12-" ] + |- call [ "sed"; "/^\\./d" ] + + +let find_sort_name () = + let open Shexp_process in + let open Shexp_process.Infix in + call [ "find"; "." ] |- call [ "sort"; "-n" ] |- call [ "cut"; "-c3-" ] + + let run_print ~dir args = let open Shexp_process in let open Shexp_process.Infix in @@ -19,10 +34,25 @@ let run_print ~dir args = let headline_args = - [ grep_cmd; "^\\*"; "-H"; "-r"; "-n"; "--separator=|"; "--no-messages" ] + [ "xargs"; grep_cmd; "^\\*"; "-H"; "-r"; "-n"; "--separator=|"; "--no-messages" ] -let get_headlines () = run_print ~dir:execution_directory headline_args +(* type sort = *) +(* | Name *) +(* | LastModified *) + +(* let sort_to_cmd = function *) +(* | Name -> find_sort_name () *) +(* | LastModified -> find_sort_modification () *) + +let get_headlines () = + let open Shexp_process in + let open Shexp_process.Infix in + eval + (chdir + execution_directory + (find_sort_modification () |- call headline_args |- read_all)) + let get_tagged_headlines tag () = let open Shexp_process in @@ -30,7 +60,10 @@ let get_tagged_headlines tag () = eval (chdir execution_directory - (call headline_args |- call [ grep_cmd; "-E"; "--no-messages"; tag ] |- read_all)) + (find_sort_name () + |- call headline_args + |- call [ grep_cmd; "-E"; "--no-messages"; tag ] + |- read_all)) let get_tags () = -- cgit v1.2.3