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)))