home: import: Properly parse aliases that contain quotes.

* guix/scripts/home/import.scm (generate-bash-configuration+modules):
Define 'alias-rx'.
[bash-alias->pair]: Use it.
* tests/home-import.scm (match-home-environment-bash-service-with-alias):
New variable.
("manifest->code: Bash service with aliases"): New test.
This commit is contained in:
Ludovic Courtès 2022-03-20 18:56:46 +01:00
parent 92c2397070
commit 6da2a5a565
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 40 additions and 6 deletions

View file

@ -1,7 +1,7 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; Copyright © 2021 Andrew Tropin <andrew@trop.in> ;;; Copyright © 2021 Andrew Tropin <andrew@trop.in>
;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2021-2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2022 Arjan Adriaanse <arjan@adriaan.se> ;;; Copyright © 2022 Arjan Adriaanse <arjan@adriaan.se>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
@ -60,12 +60,15 @@ (define (generate-bash-configuration+modules destination-directory)
(define (destination-append path) (define (destination-append path)
(string-append destination-directory "/" path)) (string-append destination-directory "/" path))
(define alias-rx
(make-regexp "^alias ([^=]+)=[\"'](.+)[\"']$"))
(define (bash-alias->pair line) (define (bash-alias->pair line)
(if (string-prefix? "alias" line) (match (regexp-exec alias-rx line)
(let ((matched (string-match "alias (.+)=\"?'?([^\"']+)\"?'?" line))) (#f '())
`(,(match:substring matched 1) . ,(match:substring matched 2))) (matched
'())) `(,(match:substring matched 1) . ,(match:substring matched 2)))))
(define (parse-aliases input) (define (parse-aliases input)
(let loop ((line (read-line input)) (let loop ((line (read-line input))
(result '())) (result '()))

View file

@ -158,6 +158,29 @@ (define-home-environment-matcher match-home-environment-bash-service
('list ('local-file "/tmp/guix-config/.bashrc" ('list ('local-file "/tmp/guix-config/.bashrc"
"bashrc")))))))))) "bashrc"))))))))))
(define-home-environment-matcher match-home-environment-bash-service-with-alias
('begin
('use-modules
('gnu 'home)
('gnu 'packages)
('gnu 'services)
('guix 'gexp)
('gnu 'home 'services 'shells))
('home-environment
('packages
('map ('compose 'list 'specification->package+output)
('list)))
('services
('list ('service
'home-bash-service-type
('home-bash-configuration
('aliases
('quote (("grep" . "grep --exclude-from=\"$HOME/.grep-exclude\"")
("ls" . "ls -p"))))
('bashrc
('list ('local-file "/tmp/guix-config/.bashrc"
"bashrc"))))))))))
(test-assert "manifest->code: No services" (test-assert "manifest->code: No services"
(eval-test-with-home-environment (eval-test-with-home-environment
@ -187,4 +210,12 @@ (define-home-environment-matcher match-home-environment-bash-service
(make-manifest '()) (make-manifest '())
match-home-environment-bash-service)) match-home-environment-bash-service))
(test-assert "manifest->code: Bash service with aliases"
(eval-test-with-home-environment
'((".bashrc"
. "# Aliases
alias ls=\"ls -p\"; alias grep='grep --exclude-from=\"$HOME/.grep-exclude\"'\n"))
(make-manifest '())
match-home-environment-bash-service-with-alias))
(test-end "home-import") (test-end "home-import")