aboutsummaryrefslogtreecommitdiff
path: root/lib/export.ml
blob: 0468e643298bb0b257fc54e859c9fd313580b221 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
let to_path path ~content =
  try
    let home = Sys.getenv_opt "HOME" in
    let path =
      match home with
      | Some home -> Str.replace_first (Str.regexp "~") home path
      | None -> path
    in
    let oc = open_out path in
    Printf.fprintf oc "%s\n" content;
    close_out oc;
    "Successfully wrote to " ^ path
  with
  | exn -> "Failed to write to path: " ^ Printexc.to_string exn