diff options
author | Ludovic Courtès <ludo@gnu.org> | 2022-03-20 18:56:46 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2022-03-20 19:02:41 +0100 |
commit | 6da2a5a5655668f42ec5b26f875ddbc498e132b6 (patch) | |
tree | dbfde9c590cd244e9ae8b25a511db4bc2870838d | |
parent | 92c23970709bc58c33b99ab9449eaf67ac5a0694 (diff) | |
download | guix-6da2a5a5655668f42ec5b26f875ddbc498e132b6.tar.gz |
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.
-rw-r--r-- | guix/scripts/home/import.scm | 15 | ||||
-rw-r--r-- | tests/home-import.scm | 31 |
2 files changed, 40 insertions, 6 deletions
diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm index 15bd3140ed..f01a98bc55 100644 --- a/guix/scripts/home/import.scm +++ b/guix/scripts/home/import.scm @@ -1,7 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> ;;; 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> ;;; ;;; This file is part of GNU Guix. @@ -60,12 +60,15 @@ FILE-NAME with \"-\", and return the basename of it." (define (destination-append path) (string-append destination-directory "/" path)) + (define alias-rx + (make-regexp "^alias ([^=]+)=[\"'](.+)[\"']$")) + (define (bash-alias->pair line) - (if (string-prefix? "alias" line) - (let ((matched (string-match "alias (.+)=\"?'?([^\"']+)\"?'?" line))) - `(,(match:substring matched 1) . ,(match:substring matched 2))) - '())) - + (match (regexp-exec alias-rx line) + (#f '()) + (matched + `(,(match:substring matched 1) . ,(match:substring matched 2))))) + (define (parse-aliases input) (let loop ((line (read-line input)) (result '())) diff --git a/tests/home-import.scm b/tests/home-import.scm index 6d373acf79..ca8aa95431 100644 --- a/tests/home-import.scm +++ b/tests/home-import.scm @@ -158,6 +158,29 @@ corresponding file." ('list ('local-file "/tmp/guix-config/.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" (eval-test-with-home-environment @@ -187,4 +210,12 @@ corresponding file." (make-manifest '()) 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") |