From: Ekaitz Zarraga <ekaitz@elenq.tech>
To: "Ludovic Courtès" <ludovic.courtes@inria.fr>
Cc: 63048@debbugs.gnu.org
Subject: bug#63048: [Home] Shell alias values are not properly quoted
Date: Mon, 24 Apr 2023 17:41:08 +0000 [thread overview]
Message-ID: <rG1_O28tWZDkb02eKEC4gH9wvuQg9BWh8rKKUmlNt6wNibGsE_WeBtjyoJ5oaLxpSJSnONPWnFPjn8pVZgWOKfy614I8hzZO6Z-7oMSL0-I=@elenq.tech> (raw)
In-Reply-To: <ysOR2QV1qAMeJ5roGVJ9dGgucalDbc-dZqiy1Fxry5G1t-db79TUwoOzEbhgJ5tIqXlxCN_pfKHi3UBf7Hz-AlFjs7XI0FYfBZUVyui_WhY=@elenq.tech>
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"))
next prev parent reply other threads:[~2023-04-24 17:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 7:57 bug#63048: [Home] Shell alias values are not properly quoted Ludovic Courtès
2023-04-24 10:10 ` Ekaitz Zarraga
2023-04-24 17:41 ` Ekaitz Zarraga [this message]
2023-07-06 15:01 ` bug#63048: [PATCH] home: services: bash: Properly quote shell aliases Ludovic Courtès
2023-07-11 15:02 ` bug#63048: [Home] Shell alias values are not properly quoted Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='rG1_O28tWZDkb02eKEC4gH9wvuQg9BWh8rKKUmlNt6wNibGsE_WeBtjyoJ5oaLxpSJSnONPWnFPjn8pVZgWOKfy614I8hzZO6Z-7oMSL0-I=@elenq.tech' \
--to=ekaitz@elenq.tech \
--cc=63048@debbugs.gnu.org \
--cc=ludovic.courtes@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).