diff options
Diffstat (limited to 'lib/util.scm')
-rw-r--r-- | lib/util.scm | 29 |
1 files changed, 24 insertions, 5 deletions
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 @@ | |||
2 | 2 | ||
3 | (import scheme (chicken base) | 3 | (import scheme (chicken base) |
4 | (chicken condition) | 4 | (chicken condition) |
5 | (only (chicken irregex) irregex-replace/all) | 5 | (chicken file) |
6 | (chicken string)) | 6 | (chicken irregex) |
7 | (chicken process-context) | ||
8 | (chicken string) | ||
9 | (srfi 1) | ||
10 | utf8-srfi-13) | ||
7 | 11 | ||
8 | (define-syntax define-public | 12 | (define-syntax define-public |
9 | (syntax-rules () | 13 | (syntax-rules () |
@@ -34,9 +38,6 @@ | |||
34 | ((list? (cdr kv)) | 38 | ((list? (cdr kv)) |
35 | (apply alist-walk (cdr kv) (cdr keys))))))) | 39 | (apply alist-walk (cdr kv) (cdr keys))))))) |
36 | 40 | ||
37 | (define (string-join ss #!optional (sep " ")) | ||
38 | (string-intersperse ss sep)) | ||
39 | |||
40 | (define (flush-lines-left lines) | 41 | (define (flush-lines-left lines) |
41 | (irregex-replace/all '(: bol (* space)) | 42 | (irregex-replace/all '(: bol (* space)) |
42 | (string-join lines) "")) | 43 | (string-join lines) "")) |
@@ -44,6 +45,24 @@ | |||
44 | (define (join-lines lines) | 45 | (define (join-lines lines) |
45 | (apply string-append lines)) | 46 | (apply string-append lines)) |
46 | 47 | ||
48 | (define (find-command command . dirs) | ||
49 | (define (find-command-in-dir dir) | ||
50 | (and (directory-exists? dir) | ||
51 | (find-files dir | ||
52 | limit: 0 | ||
53 | test: `(: (* any) "/" ,command eos)))) | ||
54 | (define path+ | ||
55 | (append (string-split (get-environment-variable "PATH") ":") dirs)) | ||
56 | (define found | ||
57 | (filter file-executable? | ||
58 | (apply append (filter-map find-command-in-dir path+)))) | ||
59 | (if (pair? found) (car found) #f)) | ||
60 | |||
61 | (define (ensure-newline str) | ||
62 | (if (string-suffix? "\n" str) | ||
63 | str | ||
64 | (string-append str "\n"))) | ||
65 | |||
47 | ) | 66 | ) |
48 | 67 | ||
49 | 68 | ||