From 5de8ba681728781c96f3d1650897ea8d7ad90dd3 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Am=C3=A9lia=20P=2E=20H=2E=20Coutard?= <amy@ameliathe1st.gay>
Date: Sat, 6 Apr 2024 17:56:44 +0200
Subject: [PATCH] Utilitaire pour lire un fichier et remplacer des noms de
 fichiers par les localisations correspondantes dans les paquets

---
 amyx/home.scm | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 amyx/home.scm

diff --git a/amyx/home.scm b/amyx/home.scm
new file mode 100644
index 0000000..f4eec34
--- /dev/null
+++ b/amyx/home.scm
@@ -0,0 +1,48 @@
+; Copyright 2023 Amélia COUTARD.
+;
+; This file from the guix channel amy is free software: you can redistribute it and/or modify it
+; under the terms of the GNU General Public License as published by the Free Software Foundation,
+; either version 3 of the License, or (at your option) any later version.
+;
+; This channel is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+; PURPOSE. See the GNU General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License along with this channel. If
+; not, see <https://www.gnu.org/licenses/>.
+
+(define-module (amyx home)
+  #:use-module (ice-9 exceptions)
+  #:use-module (ice-9 regex)
+  #:use-module (ice-9 textual-ports)
+  #:use-module (srfi srfi-1)
+  #:export (replace-store-files))
+
+(define (find-file-in-packages f packages)
+  (let ((l (filter-map (lambda (p)
+                         (and (stat (string-append p "/" f) #f)
+                              (string-append p "/" f))) packages)))
+    (cond
+      ((= (length l) 0)
+       (raise-exception (make-exception (make-error)
+                                        (make-exception-with-message (string-append
+                                                                      "File found in no packages: "
+                                                                      f)))))
+      ((= (length l) 1)
+       (car l))
+      (else (raise-exception (make-exception (make-error)
+                                             (make-exception-with-message (string-append
+                                                                           "File found in multiple packages: "
+                                                                           f))))))))
+
+(define (replace-store-files file packages)
+  (regexp-substitute/global #f
+                            "#\\$([^ \n\t]*)"
+                            (call-with-input-file file
+                              get-string-all)
+                            'pre
+                            (lambda (m)
+                              (find-file-in-packages (match:substring m 1)
+                                                     packages))
+                            'post))
+
-- 
2.46.0