diff options
Diffstat (limited to 'deepenv.scm')
-rw-r--r-- | deepenv.scm | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/deepenv.scm b/deepenv.scm index 37082ad..fb7bae2 100644 --- a/deepenv.scm +++ b/deepenv.scm @@ -4,20 +4,44 @@ (chicken file) (chicken io) (chicken string) - (srfi srfi-13) - (chicken process-context)) + (chicken process-context) + srfi-13 + srfi-14) (define (dir-has-.env? dir) (file-exists? (make-pathname dir ".env"))) +(define (split-env-line line) + (let* ((definition (string-split line "=")) + (key (car definition)) + (value (string-trim-both (cadr definition) + (list->char-set (list #\") char-set:whitespace)))) + (cons key value))) + (define (read-env-line port) "Read an env-definition line from PORT and return as a cons cell" (let ((line (read-line port))) - (string-split line "="))) + (if (eq? line #!eof) + #!eof + (split-env-line line)))) (define (load-dir-.env dir) "Load a .env file present in `.dir` and return its environment definitions as a alist" (with-input-from-file ".env" - (lambda () (read-list (current-input-port) read-line)))) + (lambda () (read-list (current-input-port) read-env-line)))) + +(define (path-parents path) + (call-with-values + (lambda () (decompose-directory path)) + (lambda (origin base elts) + (if (not (eq? origin #f)) + (cons origin elts) + (if (not (eq? base #f)) + (cons base elts) + elts))))) + + + +(let ((path-hierarchy (path-parents (current-directory)))) + path-hierarchy) -(letrec ((path-hierarchy (decompose-directory (current-directory))))) |