aboutsummaryrefslogtreecommitdiff
path: root/lib/grep.ml
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2024-05-14 11:21:26 -0500
committerMarc Coquand <marc@mccd.space>2024-05-14 11:21:26 -0500
commit89817d53ec7dbf5cff9c873afe9b7bc939dbe8c3 (patch)
tree113496e6715ff830ff4659806a95a2085fa7d906 /lib/grep.ml
parentbe2bf751536850e7bdfbd876ef908c5d6cf00087 (diff)
downloadstitch-89817d53ec7dbf5cff9c873afe9b7bc939dbe8c3.tar.gz
stitch-89817d53ec7dbf5cff9c873afe9b7bc939dbe8c3.tar.bz2
stitch-89817d53ec7dbf5cff9c873afe9b7bc939dbe8c3.zip
Add sort algorithms
Diffstat (limited to 'lib/grep.ml')
-rw-r--r--lib/grep.ml39
1 files 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 () =