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.
This commit is contained in:
Tom Willemsen 2012-08-17 01:26:52 +02:00
parent 88212abab3
commit 206294033b

View file

@ -57,7 +57,15 @@
where #t where #t
sort-by #f nil))))) 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 (define rc-file
(let* ((xdg (getenv "XDG_CONFIG_HOME")) (let* ((xdg (getenv "XDG_CONFIG_HOME"))
@ -95,8 +103,18 @@
(string-append (getenv "HOME") "/.")) (string-append (getenv "HOME") "/."))
"undone"))) "undone")))
(define (mkdirs path)
(let ((parent (dirname path)))
(if (not (file-exists? parent))
(mkdirs parent)))
(if (not (file-exists? path))
(mkdir path)))
(define (save) (define (save)
"Save the list." "Save the list."
(mkdirs (dirname todo-list-file))
(let ((port (open-output-file todo-list-file))) (let ((port (open-output-file todo-list-file)))
(write todo-list port) (write todo-list port)
(close-port port))) (close-port port)))