mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
home: services: shells: Double-quote environment variable values.
Fixes <https://issues.guix.gnu.org/56540>. Until now, environment variable values were emitted unquoted, producing invalid shell code if the value contains spaces for example. * gnu/home/services/shells.scm (serialize-posix-env-vars): Define 'shell-quote' procedure in staged code and use it for #$value. * tests/guix-home.sh: Add test for PS1 variable with a value containing spaces.
This commit is contained in:
parent
9e4cbb3076
commit
8af749224f
2 changed files with 27 additions and 10 deletions
|
@ -111,16 +111,30 @@ (define home-shell-profile-service-type
|
|||
|
||||
(define (serialize-boolean field-name val) "")
|
||||
(define (serialize-posix-env-vars field-name val)
|
||||
#~(string-append
|
||||
#$@(map
|
||||
(match-lambda
|
||||
((key . #f)
|
||||
"")
|
||||
((key . #t)
|
||||
#~(string-append "export " #$key "\n"))
|
||||
((key . value)
|
||||
#~(string-append "export " #$key "=" #$value "\n")))
|
||||
val)))
|
||||
#~(let ((shell-quote
|
||||
(lambda (value)
|
||||
;; Double-quote VALUE, leaving dollar sign as is.
|
||||
(let ((quoted (list->string
|
||||
(string-fold-right
|
||||
(lambda (chr lst)
|
||||
(case chr
|
||||
((#\" #\\)
|
||||
(append (list chr #\\) lst))
|
||||
(else (cons chr lst))))
|
||||
'()
|
||||
value))))
|
||||
(string-append "\"" quoted "\"")))))
|
||||
(string-append
|
||||
#$@(map
|
||||
(match-lambda
|
||||
((key . #f)
|
||||
"")
|
||||
((key . #t)
|
||||
#~(string-append "export " #$key "\n"))
|
||||
((key . value)
|
||||
#~(string-append "export " #$key "="
|
||||
(shell-quote #$value) "\n")))
|
||||
val))))
|
||||
|
||||
|
||||
;;;
|
||||
|
|
|
@ -82,6 +82,8 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
|
|||
(simple-service 'home-bash-service-extension-test
|
||||
home-bash-service-type
|
||||
(home-bash-extension
|
||||
(environment-variables
|
||||
'(("PS1" . "$GUIX_ENVIRONMENT λ ")))
|
||||
(bashrc
|
||||
(list
|
||||
(plain-file
|
||||
|
@ -138,6 +140,7 @@ EOF
|
|||
# dot-bashrc test file for guix home
|
||||
# the content of bashrc-test-config.sh"
|
||||
grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.conf"
|
||||
grep '^export PS1="\$GUIX_ENVIRONMENT λ "$' "${HOME}/.bash_profile"
|
||||
|
||||
# This one should still be here.
|
||||
grep "stay around" "$HOME/.config/random-file"
|
||||
|
|
Loading…
Reference in a new issue