aboutsummaryrefslogtreecommitdiff
path: root/lib/export.ml
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2024-05-23 14:04:23 -0500
committerMarc Coquand <marc@mccd.space>2024-05-23 14:04:23 -0500
commit527e025e88fc01c7ed4fc3f951484b051c264d83 (patch)
tree825a8751d30725e299ac363698a7a5f86d5ac535 /lib/export.ml
parenteed9e36b661009e5bcf1c4f5ec3a9279bbb7cda5 (diff)
downloadstitch-527e025e88fc01c7ed4fc3f951484b051c264d83.tar.gz
stitch-527e025e88fc01c7ed4fc3f951484b051c264d83.tar.bz2
stitch-527e025e88fc01c7ed4fc3f951484b051c264d83.zip
Fix export with relative line
Diffstat (limited to 'lib/export.ml')
-rw-r--r--lib/export.ml16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/export.ml b/lib/export.ml
index 3346195..0468e64 100644
--- a/lib/export.ml
+++ b/lib/export.ml
@@ -1,4 +1,14 @@
let to_path path ~content =
- let oc = open_out path in
- Printf.fprintf oc "%s" content;
- close_out oc
+ 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