(import scheme (chicken base) (chicken pathname) (chicken file) (chicken io) (chicken string) (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))) (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-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)