From 0c0fd191cae63cfd6c4b905837e381cad9bab2a4 Mon Sep 17 00:00:00 2001 From: anemofilia Date: Sat, 26 Aug 2023 11:18:24 -0300 Subject: [PATCH] feat: add a (radix combinators) module --- modules/radix/combinators.scm | 41 +++++++++++++++++++++++++++++++++++ modules/radix/files/fish.scm | 32 +++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 modules/radix/combinators.scm diff --git a/modules/radix/combinators.scm b/modules/radix/combinators.scm new file mode 100644 index 0000000..5879a9f --- /dev/null +++ b/modules/radix/combinators.scm @@ -0,0 +1,41 @@ +(define-module (radix combinators) + #:use-module (srfi srfi-26) + #:use-module (ice-9 match) + #:export (all? + any? + conjoin + disjoin + inclusive-disjoin)) + +(define (all? pred lst) + (null? (filter null? (map pred lst)))) + +(define (any? pred lst) + (cond ((null? lst) #f) + ((pred (car lst)) #t) + (else (any? pred (cdr lst))))) + +#| (conjoin (list (conjoin '()) predicates)) = (conjoin predicates) |# +(define (conjoin . predicates) + (lambda args + (if (null? predicates) #t + (match-let loop (((head-pred . tail-preds) predicates)) + (cond ((null? tail-preds) (apply head-pred args)) + ((apply head-pred args) (loop tail-preds)) + (else #f)))))) + +#| (disjoin (list (disjoin '()) predicates)) = (disjoin predicates) |# +(define (disjoin . predicates) + (lambda args + (if (null? predicates) #f + (null? (cdr (filter (cut apply <> args) + predicates)))))) + +(define (inclusive-disjoin . predicates) + (lambda args + (if (null? predicates) #f + (match-let loop (((head-pred . tail-preds) predicates)) + (cond ((null? tail-preds) (apply head-pred args)) + ((not (apply head-pred args)) (loop tail-preds)) + (else #f)))))) + diff --git a/modules/radix/files/fish.scm b/modules/radix/files/fish.scm index cb5ea92..602a812 100644 --- a/modules/radix/files/fish.scm +++ b/modules/radix/files/fish.scm @@ -1,5 +1,8 @@ (define-module (radix files fish) #:use-module (gnu) + #:use-module (ice-9 ftw) + #:use-module (ice-9 rdelim) + #:use-module (radix combinators) #:use-module (gnu packages shells) #:export (abbreviations fenv @@ -19,6 +22,31 @@ (define variables (local-file "../../../files/fish/variables.fish")) +(define fenv-dir + (run-with-store (open-connection) + (package-file fish-foreign-env))) + +(define fenv-files + (map (cut string-append fenv-dir "/share/fish/functions/" <>) + (filter (negate (cut string-prefix? "." <>)) + (scandir (string-append fenv-dir + "/share/fish/functions"))))) + +(define (remove-unimportant-lines str) + (string-join + (filter (negate (inclusive-disjoin + string-null? + (cut string-prefix? "#" <>))) + (string-split str #\newline)) + "\n")) + (define fenv - (file-append fish-foreign-env - "/share/fish/functions/fenv.fish")) + (plain-file "fenv" + (string-join + (map (lambda (file) + (let* ((port (open-input-file file)) + (content (read-string port))) + (close-input-port port) + (remove-unimportant-lines content))) + fenv-files) + "\n")))