diff options
-rw-r--r-- | .env | 2 | ||||
-rw-r--r-- | deepenv.scm | 19 |
2 files changed, 20 insertions, 1 deletions
@@ -0,0 +1,2 @@ +FOO=123 +BAR="KOIN" diff --git a/deepenv.scm b/deepenv.scm index 6e81a46..37082ad 100644 --- a/deepenv.scm +++ b/deepenv.scm @@ -1,6 +1,23 @@ (import scheme (chicken base) (chicken pathname) + (chicken file) + (chicken io) + (chicken string) + (srfi srfi-13) (chicken process-context)) -(decompose-directory (current-directory)) +(define (dir-has-.env? dir) + (file-exists? (make-pathname dir ".env"))) + +(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 "="))) + +(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)))) + +(letrec ((path-hierarchy (decompose-directory (current-directory))))) |