From d61e3814a5791ab75201c1c00b3e7bf76c3dbd83 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sun, 12 May 2013 22:14:12 +0200 Subject: Add write-config This procedure writes a configuration alist to a format understood by git. --- gitto/config.scm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gitto/config.scm b/gitto/config.scm index 1ba199e..14151f6 100644 --- a/gitto/config.scm +++ b/gitto/config.scm @@ -19,7 +19,7 @@ (define-module (gitto config) #:use-module (ice-9 rdelim) - #:export (read-config)) + #:export (read-config write-config)) (define (parse-setting line) (let ((idx (string-index line #\=))) @@ -45,3 +45,16 @@ (parse-setting line)))))) (close-port port) config)) + +(define* (write-config config #:optional (file #f)) + (let ((thunk (lambda () (for-each write-section config)))) + (if file + (with-output-to-file file thunk) + (thunk)))) + +(define (write-section section) + (format #t "[~a]~%" (car section)) + (for-each write-setting (cdr section))) + +(define (write-setting setting) + (format #t "~8t~a = ~a~%" (car setting) (cdr setting))) -- cgit v1.3-2-g0d8e