From 703e9e93087d32364087a0ebc9e315869b70ff7c Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 15 Jun 2024 21:17:03 -0500 Subject: Update things --- lib/util.scm | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'lib/util.scm') diff --git a/lib/util.scm b/lib/util.scm index c71c600..f42878b 100644 --- a/lib/util.scm +++ b/lib/util.scm @@ -2,8 +2,12 @@ (import scheme (chicken base) (chicken condition) - (only (chicken irregex) irregex-replace/all) - (chicken string)) + (chicken file) + (chicken irregex) + (chicken process-context) + (chicken string) + (srfi 1) + utf8-srfi-13) (define-syntax define-public (syntax-rules () @@ -34,9 +38,6 @@ ((list? (cdr kv)) (apply alist-walk (cdr kv) (cdr keys))))))) - (define (string-join ss #!optional (sep " ")) - (string-intersperse ss sep)) - (define (flush-lines-left lines) (irregex-replace/all '(: bol (* space)) (string-join lines) "")) @@ -44,6 +45,24 @@ (define (join-lines lines) (apply string-append lines)) + (define (find-command command . dirs) + (define (find-command-in-dir dir) + (and (directory-exists? dir) + (find-files dir + limit: 0 + test: `(: (* any) "/" ,command eos)))) + (define path+ + (append (string-split (get-environment-variable "PATH") ":") dirs)) + (define found + (filter file-executable? + (apply append (filter-map find-command-in-dir path+)))) + (if (pair? found) (car found) #f)) + + (define (ensure-newline str) + (if (string-suffix? "\n" str) + str + (string-append str "\n"))) + ) -- cgit 1.4.1-21-gabe81