aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deepenv.scm21
-rw-r--r--dispenv.scm10
2 files changed, 28 insertions, 3 deletions
diff --git a/deepenv.scm b/deepenv.scm
index ae0b3c3..e22d9d0 100644
--- a/deepenv.scm
+++ b/deepenv.scm
@@ -4,6 +4,7 @@
(chicken file)
(chicken io)
(chicken string)
+ (chicken process)
(chicken process-context)
srfi-1
srfi-13
@@ -58,7 +59,21 @@
(lset-union (lambda (a b) (string=? (car a) (car b)))
alist2 alist1))
-(let ((parents (path-parents (current-directory))))
- (fold .env-union '()
- (reverse (map load-dir-.env parents))))
+(define (resolve-program program)
+ (let* ((paths (map
+ (lambda (path)
+ (conc path "/" program))
+ (string-split (get-environment-variable "PATH") ":")))
+ (executables (filter file-exists? paths)))
+ (if (> (length executables) 0)
+ (car executables)
+ program)))
+
+(let* ((parents (path-parents (current-directory)))
+ (environment (fold .env-union '() (cons (get-environment-variables) (reverse (map load-dir-.env parents)))))
+ (program (resolve-program (car (command-line-arguments))))
+ (arguments (cdr (command-line-arguments))))
+ (if program
+ (process-execute program arguments environment)
+ (display "Program not found\n")))
diff --git a/dispenv.scm b/dispenv.scm
new file mode 100644
index 0000000..fb6ed68
--- /dev/null
+++ b/dispenv.scm
@@ -0,0 +1,10 @@
+(import scheme
+ (chicken format)
+ (chicken process-context)
+ srfi-1)
+
+(define (print-env env-cons)
+ (printf "~a=~a~%" (car env-cons) (cdr env-cons)))
+
+(let ((env-vars (get-environment-variables)))
+ (for-each print-env env-vars))