mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-26 22:38:07 -05:00
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:
parent
6da2a5a565
commit
3748c32b13
1 changed files with 11 additions and 9 deletions
|
@ -65,17 +65,19 @@ (define alias-rx
|
|||
|
||||
(define (bash-alias->pair line)
|
||||
(match (regexp-exec alias-rx line)
|
||||
(#f '())
|
||||
(#f #f)
|
||||
(matched
|
||||
`(,(match:substring matched 1) . ,(match:substring matched 2)))))
|
||||
|
||||
(define (parse-aliases input)
|
||||
(let loop ((line (read-line input))
|
||||
(result '()))
|
||||
(if (eof-object? line)
|
||||
(reverse result)
|
||||
(loop (read-line input)
|
||||
(cons (bash-alias->pair line) result)))))
|
||||
(let loop ((result '()))
|
||||
(match (read-line input)
|
||||
((? eof-object?)
|
||||
(reverse result))
|
||||
(line
|
||||
(match (bash-alias->pair line)
|
||||
(#f (loop result))
|
||||
(alias (loop (cons alias result))))))))
|
||||
|
||||
(let ((rc (destination-append ".bashrc"))
|
||||
(profile (destination-append ".bash_profile"))
|
||||
|
@ -85,9 +87,9 @@ (define (parse-aliases input)
|
|||
,@(if (file-exists? rc)
|
||||
`((aliases
|
||||
',(let* ((port (open-pipe* OPEN_READ "bash" "-i" "-c" "alias"))
|
||||
(alist (parse-aliases port)))
|
||||
(alist (parse-aliases port)))
|
||||
(close-port port)
|
||||
(filter (negate null?) alist))))
|
||||
alist)))
|
||||
'())
|
||||
,@(if (file-exists? rc)
|
||||
`((bashrc
|
||||
|
|
Loading…
Reference in a new issue