home: import: Clarify alias parsing code.

* guix/scripts/home/import.scm (generate-bash-configuration+modules)
[bash-alias->pair]: Return #f on match failure.
[parse-aliases]: Adjust accordingly and use 'match'.
Remove 'filter' call.
This commit is contained in:
Ludovic Courtès 2022-03-20 18:59:47 +01:00
parent 6da2a5a565
commit 3748c32b13
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -65,17 +65,19 @@ (define alias-rx
(define (bash-alias->pair line) (define (bash-alias->pair line)
(match (regexp-exec alias-rx line) (match (regexp-exec alias-rx line)
(#f '()) (#f #f)
(matched (matched
`(,(match:substring matched 1) . ,(match:substring matched 2))))) `(,(match:substring matched 1) . ,(match:substring matched 2)))))
(define (parse-aliases input) (define (parse-aliases input)
(let loop ((line (read-line input)) (let loop ((result '()))
(result '())) (match (read-line input)
(if (eof-object? line) ((? eof-object?)
(reverse result) (reverse result))
(loop (read-line input) (line
(cons (bash-alias->pair line) result))))) (match (bash-alias->pair line)
(#f (loop result))
(alias (loop (cons alias result))))))))
(let ((rc (destination-append ".bashrc")) (let ((rc (destination-append ".bashrc"))
(profile (destination-append ".bash_profile")) (profile (destination-append ".bash_profile"))
@ -85,9 +87,9 @@ (define (parse-aliases input)
,@(if (file-exists? rc) ,@(if (file-exists? rc)
`((aliases `((aliases
',(let* ((port (open-pipe* OPEN_READ "bash" "-i" "-c" "alias")) ',(let* ((port (open-pipe* OPEN_READ "bash" "-i" "-c" "alias"))
(alist (parse-aliases port))) (alist (parse-aliases port)))
(close-port port) (close-port port)
(filter (negate null?) alist)))) alist)))
'()) '())
,@(if (file-exists? rc) ,@(if (file-exists? rc)
`((bashrc `((bashrc