bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#63048: [Home] Shell alias values are not properly quoted


From: Ekaitz Zarraga
Subject: bug#63048: [Home] Shell alias values are not properly quoted
Date: Mon, 24 Apr 2023 17:41:08 +0000

I made something like this instead of reusing the code you suggested, Ludo.
But it doesn't work. I don't really know why:

diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm
index fd263c0699..2d7a7abbf2 100644
--- a/guix/scripts/home/import.scm
+++ b/guix/scripts/home/import.scm
@@ -64,12 +64,23 @@ (define (destination-append path)
   (define alias-rx
     (make-regexp "^alias ([^=]+)=[\"'](.+)[\"']$"))
 
+  (define (quote-style line)
+    (cond
+      ((string-match "^alias ([^=]+)=[\"].*$" line) 'double)
+      ((string-match "^alias ([^=]+)=['].*$" line)  'single)))
+
   (define (bash-alias->pair line)
     (match (regexp-exec alias-rx line)
       (#f #f)
       (matched
        `(,(match:substring matched 1) . ,(match:substring matched 2)))))
 
+  (define (escape-alias-body quote-style body)
+    (if (eq? quote-style 'single)
+      (let* ((escaped-dquotes (string-replace-substring  body "\"" "\\\"")))
+        (string-replace-substring escaped-dquotes "\\'" "'"))
+      body))
+
   (define (parse-aliases input)
     (let loop ((result '()))
       (match (read-line input)
@@ -78,7 +89,7 @@ (define (parse-aliases input)
         (line
          (match (bash-alias->pair line)
            (#f    (loop result))
-           (alias (loop (cons alias result))))))))
+           (alias (loop (cons alias (escape-alias-body (quote-style line) 
result)))))))))
 
   (let ((rc (destination-append ".bashrc"))
         (profile (destination-append ".bash_profile"))






reply via email to

[Prev in Thread] Current Thread [Next in Thread]