From 206294033b83d95b50f98d664b78afdc25fd9852 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 17 Aug 2012 01:26:52 +0200 Subject: [PATCH] Use one big file for now * undone/main.scm (todo-list-file): Check to see if we should use a file in XDG_DATA_HOME or HOME. (mkdirs): New function. (save): Ensure the directory tree exists by calling `mkdirs' first. --- undone/main.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/undone/main.scm b/undone/main.scm index 18beab3..750bf09 100644 --- a/undone/main.scm +++ b/undone/main.scm @@ -57,7 +57,15 @@ where #t sort-by #f nil))))) -(define todo-list-file "todo.scm") +(define todo-list-file + (let* ((xdg (getenv "XDG_DATA_HOME")) + (home (getenv "HOME")) + (todo-file-name "todo.scm") + (xdg-todo-file (string-append xdg "/undone/" todo-file-name)) + (home-todo-file (string-append xdg "/.undone/" todo-file-name))) + (if (and xdg (not (file-exists? home-todo-file))) + xdg-todo-file + home-todo-file))) (define rc-file (let* ((xdg (getenv "XDG_CONFIG_HOME")) @@ -95,8 +103,18 @@ (string-append (getenv "HOME") "/.")) "undone"))) +(define (mkdirs path) + (let ((parent (dirname path))) + (if (not (file-exists? parent)) + (mkdirs parent))) + + (if (not (file-exists? path)) + (mkdir path))) + (define (save) "Save the list." + (mkdirs (dirname todo-list-file)) + (let ((port (open-output-file todo-list-file))) (write todo-list port) (close-port port)))