Shells in OCaml
at main 24 lines 602 B view raw
1(* Some history implementation that can be used out of the box. *) 2module Prefix_search : Types.History = struct 3 type t = string list 4 5 let empty = [] 6 7 type entry = string 8 9 let make_entry s = s 10 let add e t = e :: t 11 12 let history ~command h = 13 if command <> "" then 14 List.filter (fun s -> String.starts_with ~prefix:command s) h 15 else h 16 17 let commands t = t 18 19 let save t path = 20 Eio.Path.save ~create:(`If_missing 0o644) path (String.concat "\n" t) 21 22 let load path = Eio.Path.load path |> String.split_on_char '\n' 23 let pp ppf = Fmt.(list ~sep:(Fmt.any "\n") string) ppf 24end