* [bug#51543] [PATCH 0/2] Some improvements to the Bash home service
@ 2021-11-01 9:43 Xinglu Chen
2021-11-01 9:45 ` [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
` (2 more replies)
0 siblings, 3 replies; 18+ messages in thread
From: Xinglu Chen @ 2021-11-01 9:43 UTC (permalink / raw)
To: 51543
[-- Attachment #1: Type: text/plain, Size: 587 bytes --]
This series adds an ‘aliases’ field to the Bash home service, and
documents the ‘home-bash-extension’ configuration record in the manual.
Xinglu Chen (2):
home: services: bash: Add ‘aliases’ field.
doc: Document ‘home-bash-extension’ configuration record.
doc/guix.texi | 38 ++++++++++++++
gnu/home/services/shells.scm | 99 ++++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 +++++++++
3 files changed, 134 insertions(+), 27 deletions(-)
base-commit: 1a80b8909a521b91d30649a011b0257d0fadc18c
--
2.33.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field.
2021-11-01 9:43 [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
@ 2021-11-01 9:45 ` Xinglu Chen
2021-11-01 9:45 ` [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
2 siblings, 0 replies; 18+ messages in thread
From: Xinglu Chen @ 2021-11-01 9:45 UTC (permalink / raw)
To: 51543
* doc/guix.texi (Shells Home Services): Document it.
* gnu/home/services/shells.scm (bash-serialize-aliases): New procedure.
(home-bash-configuration, home-bash-extension): Add ‘aliases’ field.
(home-bash-extensions): Adjust accordingly.
* guix/scripts/home/import.scm (generate-bash-configuration+modules): Populate
the ‘alias’ field.
---
doc/guix.texi | 14 ++++++
gnu/home/services/shells.scm | 85 ++++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 ++++++++++
3 files changed, 100 insertions(+), 23 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index ea1973f02c..f7312a5b30 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -36173,6 +36173,20 @@
@item @code{environment-variables} (default: @code{()}) (type: alist)
Association list of environment variables to set for the Bash session.
+@item @code{aliases} (default: @code{()}) (type: alist)
+Association list of aliases to set for the Bash session. The alias will
+automatically be quoted, so something line this:
+
+@lisp
+'((\"ls\" . \"ls -alF\"))
+@end lisp
+
+turns into
+
+@example
+alias ls=\"ls -alF\"
+@end example
+
@item @code{bash-profile} (default: @code{()}) (type: text-config)
List of file-like objects, which will be added to @file{.bash_profile}.
Used for executing user's commands at start of login shell (In most
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index e2730967b2..bd1595a041 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -305,6 +305,18 @@ (define home-zsh-service-type
;;; Bash.
;;;
+(define (bash-serialize-aliases field-name val)
+ #~(string-append
+ #$@(map
+ (match-lambda
+ ((key . #f)
+ "")
+ ((key . #t)
+ #~(string-append "alias " #$key "\n"))
+ ((key . value)
+ #~(string-append "alias " #$key "=\"" #$value "\"\n")))
+ val)))
+
(define-configuration home-bash-configuration
(package
(package bash)
@@ -317,6 +329,21 @@ (define-configuration home-bash-configuration
(alist '())
"Association list of environment variables to set for the Bash session."
serialize-posix-env-vars)
+ (aliases
+ (alist '())
+ "Association list of aliases to set for the Bash session. The alias will
+automatically be quoted, so something line this:
+
+@lisp
+'((\"ls\" . \"ls -alF\"))
+@end lisp
+
+turns into
+
+@example
+alias ls=\"ls -alF\"
+@end example"
+ bash-serialize-aliases)
(bash-profile
(text-config '())
"List of file-like objects, which will be added to @file{.bash_profile}.
@@ -387,10 +414,11 @@ (define* (file-if-not-empty field #:optional (extra-content #f))
(if (or extra-content
(not (null? ((configuration-field-getter field-obj) config))))
`(,(object->snake-case-string file-name)
- ,(mixed-text-file
+ ,(apply mixed-text-file
(object->snake-case-string file-name)
- (if extra-content extra-content "")
- (serialize-field field)))
+ (append
+ (if extra-content extra-content '())
+ (list (serialize-field field)))))
'())))
(filter
@@ -413,8 +441,9 @@ (define* (file-if-not-empty field #:optional (extra-content #f))
,@(list (file-if-not-empty
'bashrc
(if (home-bash-configuration-guix-defaults? config)
- guix-bashrc
- #f))
+ (list guix-bashrc
+ (serialize-field 'aliases))
+ (list (serialize-field 'alises))))
(file-if-not-empty 'bash-logout)))))
(define (add-bash-packages config)
@@ -424,6 +453,9 @@ (define-configuration/no-serialization home-bash-extension
(environment-variables
(alist '())
"Association list of environment variables to set.")
+ (aliases
+ (alist '())
+ "Association list of aliases to set.")
(bash-profile
(text-config '())
"List of file-like objects.")
@@ -435,24 +467,31 @@ (define-configuration/no-serialization home-bash-extension
"List of file-like objects."))
(define (home-bash-extensions original-config extension-configs)
- (home-bash-configuration
- (inherit original-config)
- (environment-variables
- (append (home-bash-configuration-environment-variables original-config)
- (append-map
- home-bash-extension-environment-variables extension-configs)))
- (bash-profile
- (append (home-bash-configuration-bash-profile original-config)
- (append-map
- home-bash-extension-bash-profile extension-configs)))
- (bashrc
- (append (home-bash-configuration-bashrc original-config)
- (append-map
- home-bash-extension-bashrc extension-configs)))
- (bash-logout
- (append (home-bash-configuration-bash-logout original-config)
- (append-map
- home-bash-extension-bash-logout extension-configs)))))
+ (match original-config
+ (($ <home-bash-configuration> _ _ _ environment-variables aliases
+ bash-profile bashrc bash-logout)
+ (home-bash-configuration
+ (inherit original-config)
+ (environment-variables
+ (append environment-variables
+ (append-map
+ home-bash-extension-environment-variables extension-configs)))
+ (aliases
+ (append aliases
+ (append-map
+ home-bash-extension-aliases extension-configs)))
+ (bash-profile
+ (append bash-profile
+ (append-map
+ home-bash-extension-bash-profile extension-configs)))
+ (bashrc
+ (append bashrc
+ (append-map
+ home-bash-extension-bashrc extension-configs)))
+ (bash-logout
+ (append bash-logout
+ (append-map
+ home-bash-extension-bash-logout extension-configs)))))))
(define home-bash-service-type
(service-type (name 'home-bash)
diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm
index 7a7712dd96..68420ff7f9 100644
--- a/guix/scripts/home/import.scm
+++ b/guix/scripts/home/import.scm
@@ -27,6 +27,9 @@ (define-module (guix scripts home import)
#:use-module (gnu packages)
#:use-module (ice-9 match)
#:use-module (ice-9 pretty-print)
+ #:use-module (ice-9 rdelim)
+ #:use-module (ice-9 regex)
+ #:use-module (ice-9 popen)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (import-manifest
@@ -56,11 +59,32 @@ (define (generate-bash-configuration+modules destination-directory)
(define (destination-append path)
(string-append destination-directory "/" path))
+ (define (bash-alias->pair line)
+ (if (string-prefix? "alias" (pk line))
+ (let ((matched (string-match "alias (.+)=\"?'?([^\"']+)\"?'?" line)))
+ `(,(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 ((rc (destination-append ".bashrc"))
(profile (destination-append ".bash_profile"))
(logout (destination-append ".bash_logout")))
`((service home-bash-service-type
(home-bash-configuration
+ ,@(if (file-exists? rc)
+ `((aliases
+ ',(let* ((port (open-pipe* OPEN_READ "bash" "-i" "-c" "alias"))
+ (alist (parse-aliases port)))
+ (close-port port)
+ (filter (negate null?) alist))))
+ '())
,@(if (file-exists? rc)
`((bashrc
(list (local-file ,rc
--
2.33.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record.
2021-11-01 9:43 [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
2021-11-01 9:45 ` [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
@ 2021-11-01 9:45 ` Xinglu Chen
2021-11-01 10:45 ` Liliana Marie Prikler
2021-11-05 14:03 ` [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
2 siblings, 1 reply; 18+ messages in thread
From: Xinglu Chen @ 2021-11-01 9:45 UTC (permalink / raw)
To: 51543
* doc/guix.texi (Shells Home Services): Document ‘home-bash-extension’
configuration record.
* gnu/home/services/shells.scm (generate-home-bash-documentation): Extract
docstrings from ‘home-bash-extension’.
Fixes: <https://issues.guix.gnu.org/50991>
---
doc/guix.texi | 24 ++++++++++++++++++++++++
gnu/home/services/shells.scm | 14 ++++++++++----
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index f7312a5b30..a3b440f5c9 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -36206,7 +36206,31 @@
process for example).
@end table
+@end deftp
+
+To extend the Bash service, one has to use a @code{home-bash-extension},
+which contains mostly the same fields as @code{home-bash-configuration}.
+
+@deftp {Data Type} home-bash-extension
+Available @code{home-bash-extension} fields are:
+
+@table @asis
+@item @code{environment-variables} (default: @code{()}) (type: alist)
+Association list of environment variables to set.
+
+@item @code{aliases} (default: @code{()}) (type: alist)
+Association list of aliases to set.
+@item @code{bash-profile} (default: @code{()}) (type: text-config)
+List of file-like objects.
+
+@item @code{bashrc} (default: @code{()}) (type: text-config)
+List of file-like objects.
+
+@item @code{bash-logout} (default: @code{()}) (type: text-config)
+List of file-like objects.
+
+@end table
@end deftp
@subsubheading Zsh Home Service
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index bd1595a041..9eeb7153e3 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -648,10 +648,16 @@ (define (generate-home-shell-profile-documentation)
'home-shell-profile-configuration))
(define (generate-home-bash-documentation)
- (generate-documentation
- `((home-bash-configuration
- ,home-bash-configuration-fields))
- 'home-bash-configuration))
+ (string-append
+ (generate-documentation
+ `((home-bash-configuration
+ ,home-bash-configuration-fields))
+ 'home-bash-configuration)
+ "\n\n"
+ (generate-documentation
+ `((home-bash-extension
+ ,home-bash-extension-fields))
+ 'home-bash-extension)))
(define (generate-home-zsh-documentation)
(generate-documentation
--
2.33.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record.
2021-11-01 9:45 ` [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record Xinglu Chen
@ 2021-11-01 10:45 ` Liliana Marie Prikler
2021-11-01 13:22 ` Xinglu Chen
0 siblings, 1 reply; 18+ messages in thread
From: Liliana Marie Prikler @ 2021-11-01 10:45 UTC (permalink / raw)
To: Xinglu Chen, 51543
Hi,
Am Montag, den 01.11.2021, 10:45 +0100 schrieb Xinglu Chen:
> * doc/guix.texi (Shells Home Services): Document ‘home-bash-
> extension’
> configuration record.
> * gnu/home/services/shells.scm (generate-home-bash-documentation):
> Extract
> docstrings from ‘home-bash-extension’.
>
> Fixes: <https://issues.guix.gnu.org/50991>
> ---
> doc/guix.texi | 24 ++++++++++++++++++++++++
> gnu/home/services/shells.scm | 14 ++++++++++----
> 2 files changed, 34 insertions(+), 4 deletions(-)
>
> diff --git a/doc/guix.texi b/doc/guix.texi
> index f7312a5b30..a3b440f5c9 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -36206,7 +36206,31 @@
> process for example).
>
> @end table
> +@end deftp
> +
> +To extend the Bash service, one has to use a @code{home-bash-
> extension},
> +which contains mostly the same fields as @code{home-bash-
> configuration}.
This sounds like you're forcing people to extend their services. Write
it "You can extend the bash service by using home-bash-extension, whose
fields mostly mirror that of home-bash-service".
> +@deftp {Data Type} home-bash-extension
> +Available @code{home-bash-extension} fields are:
> +
> +@table @asis
> +@item @code{environment-variables} (default: @code{()}) (type:
> alist)
> +Association list of environment variables to set.
> +
> +@item @code{aliases} (default: @code{()}) (type: alist)
> +Association list of aliases to set.
>
> +@item @code{bash-profile} (default: @code{()}) (type: text-config)
> +List of file-like objects.
> +
> +@item @code{bashrc} (default: @code{()}) (type: text-config)
> +List of file-like objects.
> +
> +@item @code{bash-logout} (default: @code{()}) (type: text-config)
> +List of file-like objects.
> +
> +@end table
> @end deftp
This documentation is a little sparse, don't you agree? Are the keys
to environment-variables strings or symbols? At which point are these
fields inserted into which files (e.g. do the aliases come before
profile or after it)?
If some field is already described as part of home-bash-service, you
might also want to link back to it, but you should still state where
the extension occurs. Is new code added to the front or to the back
for instance. (On that note, is the text-config type well-documented?)
Regards,
Liliana
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record.
2021-11-01 10:45 ` Liliana Marie Prikler
@ 2021-11-01 13:22 ` Xinglu Chen
2021-11-01 16:38 ` Liliana Marie Prikler
0 siblings, 1 reply; 18+ messages in thread
From: Xinglu Chen @ 2021-11-01 13:22 UTC (permalink / raw)
To: Liliana Marie Prikler, 51543
[-- Attachment #1: Type: text/plain, Size: 3114 bytes --]
Hi,
On Mon, Nov 01 2021, Liliana Marie Prikler wrote:
> Hi,
>
> Am Montag, den 01.11.2021, 10:45 +0100 schrieb Xinglu Chen:
>> * doc/guix.texi (Shells Home Services): Document ‘home-bash-
>> extension’
>> configuration record.
>> * gnu/home/services/shells.scm (generate-home-bash-documentation):
>> Extract
>> docstrings from ‘home-bash-extension’.
>>
>> Fixes: <https://issues.guix.gnu.org/50991>
>> ---
>> doc/guix.texi | 24 ++++++++++++++++++++++++
>> gnu/home/services/shells.scm | 14 ++++++++++----
>> 2 files changed, 34 insertions(+), 4 deletions(-)
>>
>> diff --git a/doc/guix.texi b/doc/guix.texi
>> index f7312a5b30..a3b440f5c9 100644
>> --- a/doc/guix.texi
>> +++ b/doc/guix.texi
>> @@ -36206,7 +36206,31 @@
>> process for example).
>>
>> @end table
>> +@end deftp
>> +
>> +To extend the Bash service, one has to use a @code{home-bash-
>> extension},
>> +which contains mostly the same fields as @code{home-bash-
>> configuration}.
> This sounds like you're forcing people to extend their services. Write
> it "You can extend the bash service by using home-bash-extension, whose
> fields mostly mirror that of home-bash-service".
Indeed, that sounds better.
>> +@deftp {Data Type} home-bash-extension
>> +Available @code{home-bash-extension} fields are:
>> +
>> +@table @asis
>> +@item @code{environment-variables} (default: @code{()}) (type:
>> alist)
>> +Association list of environment variables to set.
>> +
>> +@item @code{aliases} (default: @code{()}) (type: alist)
>> +Association list of aliases to set.
>>
>> +@item @code{bash-profile} (default: @code{()}) (type: text-config)
>> +List of file-like objects.
>> +
>> +@item @code{bashrc} (default: @code{()}) (type: text-config)
>> +List of file-like objects.
>> +
>> +@item @code{bash-logout} (default: @code{()}) (type: text-config)
>> +List of file-like objects.
>> +
>> +@end table
>> @end deftp
> This documentation is a little sparse, don't you agree? Are the keys
> to environment-variables strings or symbols?
The keys should be strings; the rules for
‘home-environment-variable-service-type’ apply here (see “11.3.1
Essential Home Services”).
> At which point are these fields inserted into which files (e.g. do the
> aliases come before profile or after it)?
Good question! The contents of ‘aliases’ and ‘bashrc’ are put into
~/.bashrc, in that order. The contents of ‘bash-profile’ and
‘environment-variables’ are put into ~/.bash_profile, in that order.
This doesn’t seem that consistent, is there any preference to what order
should be used?
> If some field is already described as part of home-bash-service, you
> might also want to link back to it, but you should still state where
> the extension occurs. Is new code added to the front or to the back
> for instance. (On that note, is the text-config type
> well-documented?)
I don’t think there is a way to link to ‘home-bash-configuration’ using
Texinfo; one can only link to “Shells Home Services”.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record.
2021-11-01 13:22 ` Xinglu Chen
@ 2021-11-01 16:38 ` Liliana Marie Prikler
2021-11-05 11:56 ` Xinglu Chen
0 siblings, 1 reply; 18+ messages in thread
From: Liliana Marie Prikler @ 2021-11-01 16:38 UTC (permalink / raw)
To: Xinglu Chen, 51543
Hi,
Am Montag, den 01.11.2021, 14:22 +0100 schrieb Xinglu Chen:
> [...]
>
> The keys should be strings; the rules for
> ‘home-environment-variable-service-type’ apply here (see “11.3.1
> Essential Home Services”).
You might want to explicitly state that.
> > At which point are these fields inserted into which files (e.g. do
> > the aliases come before profile or after it)?
>
> Good question! The contents of ‘aliases’ and ‘bashrc’ are put into
> ~/.bashrc, in that order. The contents of ‘bash-profile’ and
> ‘environment-variables’ are put into ~/.bash_profile, in that order.
> This doesn’t seem that consistent, is there any preference to what
> order should be used?
You can use whichever makes sense to you, I'm just pointing out that it
ought to be documented.
> > If some field is already described as part of home-bash-service,
> > you might also want to link back to it, but you should still state
> > where the extension occurs. Is new code added to the front or to
> > the back for instance. (On that note, is the text-config type
> > well-documented?)
>
> I don’t think there is a way to link to ‘home-bash-configuration’
> using Texinfo; one can only link to “Shells Home Services”.
Texinfo should support anchors, which can point to arbitrary text. Of
course one could overdo it by linking each and every field, but imho
having one link for context is better than none.
Thoughts?
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record.
2021-11-01 16:38 ` Liliana Marie Prikler
@ 2021-11-05 11:56 ` Xinglu Chen
0 siblings, 0 replies; 18+ messages in thread
From: Xinglu Chen @ 2021-11-05 11:56 UTC (permalink / raw)
To: Liliana Marie Prikler, 51543
[-- Attachment #1: Type: text/plain, Size: 1668 bytes --]
Hi,
On Mon, Nov 01 2021, Liliana Marie Prikler wrote:
> Hi,
>
> Am Montag, den 01.11.2021, 14:22 +0100 schrieb Xinglu Chen:
>> [...]
>>
>> The keys should be strings; the rules for
>> ‘home-environment-variable-service-type’ apply here (see “11.3.1
>> Essential Home Services”).
> You might want to explicitly state that.
Yes, good idea.
>> > At which point are these fields inserted into which files (e.g. do
>> > the aliases come before profile or after it)?
>>
>> Good question! The contents of ‘aliases’ and ‘bashrc’ are put into
>> ~/.bashrc, in that order. The contents of ‘bash-profile’ and
>> ‘environment-variables’ are put into ~/.bash_profile, in that order.
>> This doesn’t seem that consistent, is there any preference to what
>> order should be used?
> You can use whichever makes sense to you, I'm just pointing out that it
> ought to be documented.
>
>> > If some field is already described as part of home-bash-service,
>> > you might also want to link back to it, but you should still state
>> > where the extension occurs. Is new code added to the front or to
>> > the back for instance. (On that note, is the text-config type
>> > well-documented?)
>>
>> I don’t think there is a way to link to ‘home-bash-configuration’
>> using Texinfo; one can only link to “Shells Home Services”.
> Texinfo should support anchors, which can point to arbitrary text. Of
> course one could overdo it by linking each and every field, but imho
> having one link for context is better than none.
Ah, that would do it. Thanks for the pointer.
I will send an updated series.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 0/2] Some improvements to the Bash home service
2021-11-01 9:43 [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
2021-11-01 9:45 ` [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
2021-11-01 9:45 ` [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record Xinglu Chen
@ 2021-11-05 14:03 ` Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
` (2 more replies)
2 siblings, 3 replies; 18+ messages in thread
From: Xinglu Chen @ 2021-11-05 14:03 UTC (permalink / raw)
To: 51543; +Cc: Liliana Marie Prikler
[-- Attachment #1: Type: text/plain, Size: 660 bytes --]
Changes since v1:
* Improvements to the documentation of ‘home-bash-configuration’ and
‘home-bash-extension’.
* Reorder the serialization of the ‘guix-defaults?’, ‘alias’, and
‘bashrc’ fields.
Xinglu Chen (2):
home: services: bash: Add ‘aliases’ field.
doc: Improve documentation of the Bash home service
doc/guix.texi | 54 +++++++++++++++++-
gnu/home/services/shells.scm | 108 +++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 ++++++++
3 files changed, 153 insertions(+), 33 deletions(-)
base-commit: 0e19713c1fbfd3a01347e0d490434a53a596ed3c
--
2.33.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field.
2021-11-05 14:03 ` [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
@ 2021-11-05 14:03 ` Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 2/2] doc: Improve documentation of the Bash home service Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 0/2] Some improvements to " Xinglu Chen
2 siblings, 0 replies; 18+ messages in thread
From: Xinglu Chen @ 2021-11-05 14:03 UTC (permalink / raw)
To: 51543; +Cc: Liliana Marie Prikler
* doc/guix.texi (Shells Home Services): Document it.
* gnu/home/services/shells.scm (bash-serialize-aliases): New procedure.
(home-bash-configuration, home-bash-extension): Add ‘aliases’ field.
(home-bash-extensions): Adjust accordingly.
* guix/scripts/home/import.scm (generate-bash-configuration+modules): Populate
the ‘alias’ field.
---
doc/guix.texi | 14 ++++++
gnu/home/services/shells.scm | 83 ++++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 +++++++++++
3 files changed, 98 insertions(+), 23 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index ea1973f02c..f7312a5b30 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -36173,6 +36173,20 @@
@item @code{environment-variables} (default: @code{()}) (type: alist)
Association list of environment variables to set for the Bash session.
+@item @code{aliases} (default: @code{()}) (type: alist)
+Association list of aliases to set for the Bash session. The alias will
+automatically be quoted, so something line this:
+
+@lisp
+'((\"ls\" . \"ls -alF\"))
+@end lisp
+
+turns into
+
+@example
+alias ls=\"ls -alF\"
+@end example
+
@item @code{bash-profile} (default: @code{()}) (type: text-config)
List of file-like objects, which will be added to @file{.bash_profile}.
Used for executing user's commands at start of login shell (In most
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index e2730967b2..f24e47f762 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -305,6 +305,18 @@ (define home-zsh-service-type
;;; Bash.
;;;
+(define (bash-serialize-aliases field-name val)
+ #~(string-append
+ #$@(map
+ (match-lambda
+ ((key . #f)
+ "")
+ ((key . #t)
+ #~(string-append "alias " #$key "\n"))
+ ((key . value)
+ #~(string-append "alias " #$key "=\"" #$value "\"\n")))
+ val)))
+
(define-configuration home-bash-configuration
(package
(package bash)
@@ -317,6 +329,21 @@ (define-configuration home-bash-configuration
(alist '())
"Association list of environment variables to set for the Bash session."
serialize-posix-env-vars)
+ (aliases
+ (alist '())
+ "Association list of aliases to set for the Bash session. The alias will
+automatically be quoted, so something line this:
+
+@lisp
+'((\"ls\" . \"ls -alF\"))
+@end lisp
+
+turns into
+
+@example
+alias ls=\"ls -alF\"
+@end example"
+ bash-serialize-aliases)
(bash-profile
(text-config '())
"List of file-like objects, which will be added to @file{.bash_profile}.
@@ -387,10 +414,10 @@ (define* (file-if-not-empty field #:optional (extra-content #f))
(if (or extra-content
(not (null? ((configuration-field-getter field-obj) config))))
`(,(object->snake-case-string file-name)
- ,(mixed-text-file
+ ,(apply mixed-text-file
(object->snake-case-string file-name)
- (if extra-content extra-content "")
- (serialize-field field)))
+ (cons (serialize-field field)
+ (if extra-content extra-content '()))))
'())))
(filter
@@ -413,8 +440,8 @@ (define* (file-if-not-empty field #:optional (extra-content #f))
,@(list (file-if-not-empty
'bashrc
(if (home-bash-configuration-guix-defaults? config)
- guix-bashrc
- #f))
+ (list (serialize-field 'aliases) guix-bashrc)
+ (list (serialize-field 'alises))))
(file-if-not-empty 'bash-logout)))))
(define (add-bash-packages config)
@@ -424,6 +451,9 @@ (define-configuration/no-serialization home-bash-extension
(environment-variables
(alist '())
"Association list of environment variables to set.")
+ (aliases
+ (alist '())
+ "Association list of aliases to set.")
(bash-profile
(text-config '())
"List of file-like objects.")
@@ -435,24 +465,31 @@ (define-configuration/no-serialization home-bash-extension
"List of file-like objects."))
(define (home-bash-extensions original-config extension-configs)
- (home-bash-configuration
- (inherit original-config)
- (environment-variables
- (append (home-bash-configuration-environment-variables original-config)
- (append-map
- home-bash-extension-environment-variables extension-configs)))
- (bash-profile
- (append (home-bash-configuration-bash-profile original-config)
- (append-map
- home-bash-extension-bash-profile extension-configs)))
- (bashrc
- (append (home-bash-configuration-bashrc original-config)
- (append-map
- home-bash-extension-bashrc extension-configs)))
- (bash-logout
- (append (home-bash-configuration-bash-logout original-config)
- (append-map
- home-bash-extension-bash-logout extension-configs)))))
+ (match original-config
+ (($ <home-bash-configuration> _ _ _ environment-variables aliases
+ bash-profile bashrc bash-logout)
+ (home-bash-configuration
+ (inherit original-config)
+ (environment-variables
+ (append environment-variables
+ (append-map
+ home-bash-extension-environment-variables extension-configs)))
+ (aliases
+ (append aliases
+ (append-map
+ home-bash-extension-aliases extension-configs)))
+ (bash-profile
+ (append bash-profile
+ (append-map
+ home-bash-extension-bash-profile extension-configs)))
+ (bashrc
+ (append bashrc
+ (append-map
+ home-bash-extension-bashrc extension-configs)))
+ (bash-logout
+ (append bash-logout
+ (append-map
+ home-bash-extension-bash-logout extension-configs)))))))
(define home-bash-service-type
(service-type (name 'home-bash)
diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm
index 7a7712dd96..fbf89069a7 100644
--- a/guix/scripts/home/import.scm
+++ b/guix/scripts/home/import.scm
@@ -27,6 +27,9 @@ (define-module (guix scripts home import)
#:use-module (gnu packages)
#:use-module (ice-9 match)
#:use-module (ice-9 pretty-print)
+ #:use-module (ice-9 rdelim)
+ #:use-module (ice-9 regex)
+ #:use-module (ice-9 popen)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (import-manifest
@@ -56,11 +59,32 @@ (define (generate-bash-configuration+modules destination-directory)
(define (destination-append path)
(string-append destination-directory "/" path))
+ (define (bash-alias->pair line)
+ (if (string-prefix? "alias" line)
+ (let ((matched (string-match "alias (.+)=\"?'?([^\"']+)\"?'?" line)))
+ `(,(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 ((rc (destination-append ".bashrc"))
(profile (destination-append ".bash_profile"))
(logout (destination-append ".bash_logout")))
`((service home-bash-service-type
(home-bash-configuration
+ ,@(if (file-exists? rc)
+ `((aliases
+ ',(let* ((port (open-pipe* OPEN_READ "bash" "-i" "-c" "alias"))
+ (alist (parse-aliases port)))
+ (close-port port)
+ (filter (negate null?) alist))))
+ '())
,@(if (file-exists? rc)
`((bashrc
(list (local-file ,rc
--
2.33.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 2/2] doc: Improve documentation of the Bash home service
2021-11-05 14:03 ` [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
@ 2021-11-05 14:03 ` Xinglu Chen
2021-11-05 19:36 ` Liliana Marie Prikler
2021-11-07 11:36 ` [bug#51543] [PATCH v3 0/2] Some improvements to " Xinglu Chen
2 siblings, 1 reply; 18+ messages in thread
From: Xinglu Chen @ 2021-11-05 14:03 UTC (permalink / raw)
To: 51543; +Cc: Liliana Marie Prikler
* doc/guix.texi (Shells Home Services): Document ‘home-bash-extension’
configuration record.
* gnu/home/services/shells.scm (generate-home-bash-documentation): Extract
docstrings from ‘home-bash-extension’.
(home-bash-configuration): Expound on docstrings.
Fixes: <https://issues.guix.gnu.org/50991>
---
doc/guix.texi | 44 ++++++++++++++++++++++++++++++++----
gnu/home/services/shells.scm | 29 ++++++++++++++++--------
2 files changed, 59 insertions(+), 14 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index f7312a5b30..002193e994 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -36159,6 +36159,7 @@
@subsubheading Bash Home Service
+@anchor{home-bash-configuration}
@deftp {Data Type} home-bash-configuration
Available @code{home-bash-configuration} fields are:
@@ -36167,15 +36168,20 @@
The Bash package to use.
@item @code{guix-defaults?} (default: @code{#t}) (type: boolean)
-Add sane defaults like reading @file{/etc/bashrc}, coloring output for
-@code{ls} provided by guix to @file{.bashrc}.
+Add sane defaults like reading @file{/etc/bashrc} and coloring the output of
+@command{ls} to the end of the @file{.bashrc} file.
@item @code{environment-variables} (default: @code{()}) (type: alist)
-Association list of environment variables to set for the Bash session.
+Association list of environment variables to set for the Bash session. The
+rules for the @code{home-environment-variables-service-type} apply
+here (@pxref{Essential Home Services}). The contents of this field will be
+added after the contents of the @code{bash-profile} field.
@item @code{aliases} (default: @code{()}) (type: alist)
-Association list of aliases to set for the Bash session. The alias will
-automatically be quoted, so something line this:
+Association list of aliases to set for the Bash session. The aliases
+will be defined after the contents of the @code{bashrc} field has been
+put in the @file{.bashrc} file. The alias will automatically be quoted,
+so something line this:
@lisp
'((\"ls\" . \"ls -alF\"))
@@ -36206,7 +36212,35 @@
process for example).
@end table
+@end deftp
+
+You can extend the Bash service by using the @code{home-bash-extension}
+configuration record, whose fields most mirror that of
+@code{home-bash-configuration} (@pxref{home-bash-configuration}). The
+contents of the extensions will be added to the end of the corresponding
+Bash configuration files (@pxref{Bash Startup Files,,, bash, The GNU
+Bash Reference Manual}.
+
+@deftp {Data Type} home-bash-extension
+Available @code{home-bash-extension} fields are:
+
+@table @asis
+@item @code{environment-variables} (default: @code{()}) (type: alist)
+Association list of environment variables to set.
+
+@item @code{aliases} (default: @code{()}) (type: alist)
+Association list of aliases to set.
+@item @code{bash-profile} (default: @code{()}) (type: text-config)
+List of file-like objects.
+
+@item @code{bashrc} (default: @code{()}) (type: text-config)
+List of file-like objects.
+
+@item @code{bash-logout} (default: @code{()}) (type: text-config)
+List of file-like objects.
+
+@end table
@end deftp
@subsubheading Zsh Home Service
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index f24e47f762..9b8427da7b 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -323,16 +323,21 @@ (define-configuration home-bash-configuration
"The Bash package to use.")
(guix-defaults?
(boolean #t)
- "Add sane defaults like reading @file{/etc/bashrc}, coloring output
-for @code{ls} provided by guix to @file{.bashrc}.")
+ "Add sane defaults like reading @file{/etc/bashrc} and coloring the output of
+@command{ls} to the end of the @file{.bashrc} file.")
(environment-variables
(alist '())
- "Association list of environment variables to set for the Bash session."
+ "Association list of environment variables to set for the Bash session. The
+rules for the @code{home-environment-variables-service-type} apply
+here (@pxref{Essential Home Services}). The contents of this field will be
+added after the contents of the @code{bash-profile} field."
serialize-posix-env-vars)
(aliases
(alist '())
- "Association list of aliases to set for the Bash session. The alias will
-automatically be quoted, so something line this:
+ "Association list of aliases to set for the Bash session. The aliases will be
+defined after the contents of the @code{bashrc} field has been put in the
+@file{.bashrc} file. The alias will automatically be quoted, so something line
+this:
@lisp
'((\"ls\" . \"ls -alF\"))
@@ -646,10 +651,16 @@ (define (generate-home-shell-profile-documentation)
'home-shell-profile-configuration))
(define (generate-home-bash-documentation)
- (generate-documentation
- `((home-bash-configuration
- ,home-bash-configuration-fields))
- 'home-bash-configuration))
+ (string-append
+ (generate-documentation
+ `((home-bash-configuration
+ ,home-bash-configuration-fields))
+ 'home-bash-configuration)
+ "\n\n"
+ (generate-documentation
+ `((home-bash-extension
+ ,home-bash-extension-fields))
+ 'home-bash-extension)))
(define (generate-home-zsh-documentation)
(generate-documentation
--
2.33.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 2/2] doc: Improve documentation of the Bash home service
2021-11-05 14:03 ` [bug#51543] [PATCH 2/2] doc: Improve documentation of the Bash home service Xinglu Chen
@ 2021-11-05 19:36 ` Liliana Marie Prikler
2021-11-07 11:20 ` Xinglu Chen
0 siblings, 1 reply; 18+ messages in thread
From: Liliana Marie Prikler @ 2021-11-05 19:36 UTC (permalink / raw)
To: Xinglu Chen, 51543
Hi,
Am Freitag, den 05.11.2021, 15:03 +0100 schrieb Xinglu Chen:
> @item @code{guix-defaults?} (default: @code{#t}) (type: boolean)
> -Add sane defaults like reading @file{/etc/bashrc}, coloring output
> for
> -@code{ls} provided by guix to @file{.bashrc}.
> +Add sane defaults like reading @file{/etc/bashrc} and coloring the
> output of
> +@command{ls} to the end of the @file{.bashrc} file.
Regarding this option, you might want to instead provide a sane-
defaults-bash-service or something along those lines instead of using
an extra field. However, as this field already existed before, this is
not a blocker for this series.
> [...]
> @end table
> +@end deftp
> +
> +You can extend the Bash service by using the @code{home-bash-
> extension}
> +configuration record, whose fields most mirror that of
> +@code{home-bash-configuration} (@pxref{home-bash-
> configuration}). The
> +contents of the extensions will be added to the end of the
> corresponding
> +Bash configuration files (@pxref{Bash Startup Files,,, bash, The GNU
> +Bash Reference Manual}.
> +
> +@deftp {Data Type} home-bash-extension
> +Available @code{home-bash-extension} fields are:
> +
> +@table @asis
> +@item @code{environment-variables} (default: @code{()}) (type:
> alist)
> +Association list of environment variables to set.
> +
> +@item @code{aliases} (default: @code{()}) (type: alist)
> +Association list of aliases to set.
>
> +@item @code{bash-profile} (default: @code{()}) (type: text-config)
> +List of file-like objects.
> +
> +@item @code{bashrc} (default: @code{()}) (type: text-config)
> +List of file-like objects.
> +
> +@item @code{bash-logout} (default: @code{()}) (type: text-config)
> +List of file-like objects.
> +
> +@end table
> @end deftp
Is there a reason why this documentation stayed more or less the same?
I see the fields have an updated documentation, but it appears not to
be reflected here. Or are strings taken from the [1/2] patch?
Either way, since the data types ought to be already known, you should
write something along the lines of "Additional environment variables to
set. These will be concatenated with the environment variables from
other extensions and the base service to form one coherent block of
environment variables." and so on, focusing on what it does rather than
what it is.
Cheers
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 2/2] doc: Improve documentation of the Bash home service
2021-11-05 19:36 ` Liliana Marie Prikler
@ 2021-11-07 11:20 ` Xinglu Chen
0 siblings, 0 replies; 18+ messages in thread
From: Xinglu Chen @ 2021-11-07 11:20 UTC (permalink / raw)
To: Liliana Marie Prikler, 51543
[-- Attachment #1: Type: text/plain, Size: 2729 bytes --]
Hi,
On Fri, Nov 05 2021, Liliana Marie Prikler wrote:
> Hi,
>
> Am Freitag, den 05.11.2021, 15:03 +0100 schrieb Xinglu Chen:
>> @item @code{guix-defaults?} (default: @code{#t}) (type: boolean)
>> -Add sane defaults like reading @file{/etc/bashrc}, coloring output
>> for
>> -@code{ls} provided by guix to @file{.bashrc}.
>> +Add sane defaults like reading @file{/etc/bashrc} and coloring the
>> output of
>> +@command{ls} to the end of the @file{.bashrc} file.
> Regarding this option, you might want to instead provide a sane-
> defaults-bash-service or something along those lines instead of using
> an extra field. However, as this field already existed before, this is
> not a blocker for this series.
That sounds like a good idea!
>> [...]
>> @end table
>> +@end deftp
>> +
>> +You can extend the Bash service by using the @code{home-bash-
>> extension}
>> +configuration record, whose fields most mirror that of
>> +@code{home-bash-configuration} (@pxref{home-bash-
>> configuration}). The
>> +contents of the extensions will be added to the end of the
>> corresponding
>> +Bash configuration files (@pxref{Bash Startup Files,,, bash, The GNU
>> +Bash Reference Manual}.
>> +
>> +@deftp {Data Type} home-bash-extension
>> +Available @code{home-bash-extension} fields are:
>> +
>> +@table @asis
>> +@item @code{environment-variables} (default: @code{()}) (type:
>> alist)
>> +Association list of environment variables to set.
>> +
>> +@item @code{aliases} (default: @code{()}) (type: alist)
>> +Association list of aliases to set.
>>
>> +@item @code{bash-profile} (default: @code{()}) (type: text-config)
>> +List of file-like objects.
>> +
>> +@item @code{bashrc} (default: @code{()}) (type: text-config)
>> +List of file-like objects.
>> +
>> +@item @code{bash-logout} (default: @code{()}) (type: text-config)
>> +List of file-like objects.
>> +
>> +@end table
>> @end deftp
> Is there a reason why this documentation stayed more or less the same?
> I see the fields have an updated documentation, but it appears not to
> be reflected here. Or are strings taken from the [1/2] patch?
I didn’t change the docstrings for ‘home-bash-extension’, only for
‘home-bash-configuration’.
> Either way, since the data types ought to be already known, you should
> write something along the lines of "Additional environment variables to
> set. These will be concatenated with the environment variables from
> other extensions and the base service to form one coherent block of
> environment variables." and so on, focusing on what it does rather than
> what it is.
Yeah, that sounds a lot more informative than the current docstring.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH v3 0/2] Some improvements to the Bash home service
2021-11-05 14:03 ` [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 2/2] doc: Improve documentation of the Bash home service Xinglu Chen
@ 2021-11-07 11:36 ` Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
` (3 more replies)
2 siblings, 4 replies; 18+ messages in thread
From: Xinglu Chen @ 2021-11-07 11:36 UTC (permalink / raw)
To: 51543; +Cc: Liliana Marie Prikler
[-- Attachment #1: Type: text/plain, Size: 575 bytes --]
Changes since v2:
* Improve docstrings of ‘home-bash-extension’ fields by describing what
they do instead of what they ought to be.
Xinglu Chen (2):
home: services: bash: Add ‘aliases’ field.
doc: Improve documentation of the Bash home service
doc/guix.texi | 60 ++++++++++++++++-
gnu/home/services/shells.scm | 122 +++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 +++++++
3 files changed, 169 insertions(+), 37 deletions(-)
base-commit: 1ffc0a6be3c1613b2d99ceea098174d1f11f6f3f
--
2.33.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH v3 1/2] home: services: bash: Add ‘aliases’ field.
2021-11-07 11:36 ` [bug#51543] [PATCH v3 0/2] Some improvements to " Xinglu Chen
@ 2021-11-07 11:36 ` Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 2/2] doc: Improve documentation of the Bash home service Xinglu Chen
` (2 subsequent siblings)
3 siblings, 0 replies; 18+ messages in thread
From: Xinglu Chen @ 2021-11-07 11:36 UTC (permalink / raw)
To: 51543; +Cc: Liliana Marie Prikler
* doc/guix.texi (Shells Home Services): Document it.
* gnu/home/services/shells.scm (bash-serialize-aliases): New procedure.
(home-bash-configuration, home-bash-extension): Add ‘aliases’ field.
(home-bash-extensions): Adjust accordingly.
* guix/scripts/home/import.scm (generate-bash-configuration+modules): Populate
the ‘alias’ field.
---
doc/guix.texi | 14 ++++++
gnu/home/services/shells.scm | 83 ++++++++++++++++++++++++++----------
guix/scripts/home/import.scm | 24 +++++++++++
3 files changed, 98 insertions(+), 23 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index ea1973f02c..f7312a5b30 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -36173,6 +36173,20 @@
@item @code{environment-variables} (default: @code{()}) (type: alist)
Association list of environment variables to set for the Bash session.
+@item @code{aliases} (default: @code{()}) (type: alist)
+Association list of aliases to set for the Bash session. The alias will
+automatically be quoted, so something line this:
+
+@lisp
+'((\"ls\" . \"ls -alF\"))
+@end lisp
+
+turns into
+
+@example
+alias ls=\"ls -alF\"
+@end example
+
@item @code{bash-profile} (default: @code{()}) (type: text-config)
List of file-like objects, which will be added to @file{.bash_profile}.
Used for executing user's commands at start of login shell (In most
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index e2730967b2..f24e47f762 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -305,6 +305,18 @@ (define home-zsh-service-type
;;; Bash.
;;;
+(define (bash-serialize-aliases field-name val)
+ #~(string-append
+ #$@(map
+ (match-lambda
+ ((key . #f)
+ "")
+ ((key . #t)
+ #~(string-append "alias " #$key "\n"))
+ ((key . value)
+ #~(string-append "alias " #$key "=\"" #$value "\"\n")))
+ val)))
+
(define-configuration home-bash-configuration
(package
(package bash)
@@ -317,6 +329,21 @@ (define-configuration home-bash-configuration
(alist '())
"Association list of environment variables to set for the Bash session."
serialize-posix-env-vars)
+ (aliases
+ (alist '())
+ "Association list of aliases to set for the Bash session. The alias will
+automatically be quoted, so something line this:
+
+@lisp
+'((\"ls\" . \"ls -alF\"))
+@end lisp
+
+turns into
+
+@example
+alias ls=\"ls -alF\"
+@end example"
+ bash-serialize-aliases)
(bash-profile
(text-config '())
"List of file-like objects, which will be added to @file{.bash_profile}.
@@ -387,10 +414,10 @@ (define* (file-if-not-empty field #:optional (extra-content #f))
(if (or extra-content
(not (null? ((configuration-field-getter field-obj) config))))
`(,(object->snake-case-string file-name)
- ,(mixed-text-file
+ ,(apply mixed-text-file
(object->snake-case-string file-name)
- (if extra-content extra-content "")
- (serialize-field field)))
+ (cons (serialize-field field)
+ (if extra-content extra-content '()))))
'())))
(filter
@@ -413,8 +440,8 @@ (define* (file-if-not-empty field #:optional (extra-content #f))
,@(list (file-if-not-empty
'bashrc
(if (home-bash-configuration-guix-defaults? config)
- guix-bashrc
- #f))
+ (list (serialize-field 'aliases) guix-bashrc)
+ (list (serialize-field 'alises))))
(file-if-not-empty 'bash-logout)))))
(define (add-bash-packages config)
@@ -424,6 +451,9 @@ (define-configuration/no-serialization home-bash-extension
(environment-variables
(alist '())
"Association list of environment variables to set.")
+ (aliases
+ (alist '())
+ "Association list of aliases to set.")
(bash-profile
(text-config '())
"List of file-like objects.")
@@ -435,24 +465,31 @@ (define-configuration/no-serialization home-bash-extension
"List of file-like objects."))
(define (home-bash-extensions original-config extension-configs)
- (home-bash-configuration
- (inherit original-config)
- (environment-variables
- (append (home-bash-configuration-environment-variables original-config)
- (append-map
- home-bash-extension-environment-variables extension-configs)))
- (bash-profile
- (append (home-bash-configuration-bash-profile original-config)
- (append-map
- home-bash-extension-bash-profile extension-configs)))
- (bashrc
- (append (home-bash-configuration-bashrc original-config)
- (append-map
- home-bash-extension-bashrc extension-configs)))
- (bash-logout
- (append (home-bash-configuration-bash-logout original-config)
- (append-map
- home-bash-extension-bash-logout extension-configs)))))
+ (match original-config
+ (($ <home-bash-configuration> _ _ _ environment-variables aliases
+ bash-profile bashrc bash-logout)
+ (home-bash-configuration
+ (inherit original-config)
+ (environment-variables
+ (append environment-variables
+ (append-map
+ home-bash-extension-environment-variables extension-configs)))
+ (aliases
+ (append aliases
+ (append-map
+ home-bash-extension-aliases extension-configs)))
+ (bash-profile
+ (append bash-profile
+ (append-map
+ home-bash-extension-bash-profile extension-configs)))
+ (bashrc
+ (append bashrc
+ (append-map
+ home-bash-extension-bashrc extension-configs)))
+ (bash-logout
+ (append bash-logout
+ (append-map
+ home-bash-extension-bash-logout extension-configs)))))))
(define home-bash-service-type
(service-type (name 'home-bash)
diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm
index 7a7712dd96..fbf89069a7 100644
--- a/guix/scripts/home/import.scm
+++ b/guix/scripts/home/import.scm
@@ -27,6 +27,9 @@ (define-module (guix scripts home import)
#:use-module (gnu packages)
#:use-module (ice-9 match)
#:use-module (ice-9 pretty-print)
+ #:use-module (ice-9 rdelim)
+ #:use-module (ice-9 regex)
+ #:use-module (ice-9 popen)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (import-manifest
@@ -56,11 +59,32 @@ (define (generate-bash-configuration+modules destination-directory)
(define (destination-append path)
(string-append destination-directory "/" path))
+ (define (bash-alias->pair line)
+ (if (string-prefix? "alias" line)
+ (let ((matched (string-match "alias (.+)=\"?'?([^\"']+)\"?'?" line)))
+ `(,(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 ((rc (destination-append ".bashrc"))
(profile (destination-append ".bash_profile"))
(logout (destination-append ".bash_logout")))
`((service home-bash-service-type
(home-bash-configuration
+ ,@(if (file-exists? rc)
+ `((aliases
+ ',(let* ((port (open-pipe* OPEN_READ "bash" "-i" "-c" "alias"))
+ (alist (parse-aliases port)))
+ (close-port port)
+ (filter (negate null?) alist))))
+ '())
,@(if (file-exists? rc)
`((bashrc
(list (local-file ,rc
--
2.33.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH v3 2/2] doc: Improve documentation of the Bash home service
2021-11-07 11:36 ` [bug#51543] [PATCH v3 0/2] Some improvements to " Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
@ 2021-11-07 11:36 ` Xinglu Chen
2021-11-07 20:18 ` Liliana Marie Prikler
2021-11-07 20:58 ` bug#51543: [PATCH 0/2] Some improvements to " Ludovic Courtès
2021-11-13 20:35 ` [bug#51543] " Ludovic Courtès
3 siblings, 1 reply; 18+ messages in thread
From: Xinglu Chen @ 2021-11-07 11:36 UTC (permalink / raw)
To: 51543; +Cc: Liliana Marie Prikler
* doc/guix.texi (Shells Home Services): Document ‘home-bash-extension’
configuration record.
* gnu/home/services/shells.scm (generate-home-bash-documentation): Extract
docstrings from ‘home-bash-extension’.
(home-bash-configuration): Expound on docstrings.
(home-bash-extension): Likewise.
Fixes: <https://issues.guix.gnu.org/50991>
---
doc/guix.texi | 50 ++++++++++++++++++++++++++++++++----
gnu/home/services/shells.scm | 45 ++++++++++++++++++++++----------
2 files changed, 76 insertions(+), 19 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index f7312a5b30..db1bf6efa7 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -36159,6 +36159,7 @@
@subsubheading Bash Home Service
+@anchor{home-bash-configuration}
@deftp {Data Type} home-bash-configuration
Available @code{home-bash-configuration} fields are:
@@ -36167,15 +36168,20 @@
The Bash package to use.
@item @code{guix-defaults?} (default: @code{#t}) (type: boolean)
-Add sane defaults like reading @file{/etc/bashrc}, coloring output for
-@code{ls} provided by guix to @file{.bashrc}.
+Add sane defaults like reading @file{/etc/bashrc} and coloring the output of
+@command{ls} to the end of the @file{.bashrc} file.
@item @code{environment-variables} (default: @code{()}) (type: alist)
-Association list of environment variables to set for the Bash session.
+Association list of environment variables to set for the Bash session. The
+rules for the @code{home-environment-variables-service-type} apply
+here (@pxref{Essential Home Services}). The contents of this field will be
+added after the contents of the @code{bash-profile} field.
@item @code{aliases} (default: @code{()}) (type: alist)
-Association list of aliases to set for the Bash session. The alias will
-automatically be quoted, so something line this:
+Association list of aliases to set for the Bash session. The aliases
+will be defined after the contents of the @code{bashrc} field has been
+put in the @file{.bashrc} file. The alias will automatically be quoted,
+so something line this:
@lisp
'((\"ls\" . \"ls -alF\"))
@@ -36206,7 +36212,41 @@
process for example).
@end table
+@end deftp
+
+You can extend the Bash service by using the @code{home-bash-extension}
+configuration record, whose fields most mirror that of
+@code{home-bash-configuration} (@pxref{home-bash-configuration}). The
+contents of the extensions will be added to the end of the corresponding
+Bash configuration files (@pxref{Bash Startup Files,,, bash, The GNU
+Bash Reference Manual}.
+
+@deftp {Data Type} home-bash-extension
+Available @code{home-bash-extension} fields are:
+
+@table @asis
+@item @code{environment-variables} (default: @code{()}) (type: alist)
+Additional environment variables to set. These will be combined with the
+environment variables from other extensions and the base service to form one
+coherent block of environment variables.
+
+@item @code{aliases} (default: @code{()}) (type: alist)
+Additional aliases to set. These will be combined with the aliases from
+other extensions and the base service.
+@item @code{bash-profile} (default: @code{()}) (type: text-config)
+Additional text blocks to add to @file{.bash_profile}, which will be combined
+with text blocks from other extensions and the base service.
+
+@item @code{bashrc} (default: @code{()}) (type: text-config)
+Additional text blocks to add to @file{.bashrc}, which will be combined
+with text blocks from other extensions and the base service.
+
+@item @code{bash-logout} (default: @code{()}) (type: text-config)
+Additional text blocks to add to @file{.bash_logout}, which will be combined
+with text blocks from other extensions and the base service.
+
+@end table
@end deftp
@subsubheading Zsh Home Service
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index f24e47f762..81d07da86c 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -323,16 +323,21 @@ (define-configuration home-bash-configuration
"The Bash package to use.")
(guix-defaults?
(boolean #t)
- "Add sane defaults like reading @file{/etc/bashrc}, coloring output
-for @code{ls} provided by guix to @file{.bashrc}.")
+ "Add sane defaults like reading @file{/etc/bashrc} and coloring the output of
+@command{ls} to the end of the @file{.bashrc} file.")
(environment-variables
(alist '())
- "Association list of environment variables to set for the Bash session."
+ "Association list of environment variables to set for the Bash session. The
+rules for the @code{home-environment-variables-service-type} apply
+here (@pxref{Essential Home Services}). The contents of this field will be
+added after the contents of the @code{bash-profile} field."
serialize-posix-env-vars)
(aliases
(alist '())
- "Association list of aliases to set for the Bash session. The alias will
-automatically be quoted, so something line this:
+ "Association list of aliases to set for the Bash session. The aliases will be
+defined after the contents of the @code{bashrc} field has been put in the
+@file{.bashrc} file. The alias will automatically be quoted, so something line
+this:
@lisp
'((\"ls\" . \"ls -alF\"))
@@ -450,19 +455,25 @@ (define (add-bash-packages config)
(define-configuration/no-serialization home-bash-extension
(environment-variables
(alist '())
- "Association list of environment variables to set.")
+ "Additional environment variables to set. These will be combined with the
+environment variables from other extensions and the base service to form one
+coherent block of environment variables.")
(aliases
(alist '())
- "Association list of aliases to set.")
+ "Additional aliases to set. These will be combined with the aliases from
+other extensions and the base service.")
(bash-profile
(text-config '())
- "List of file-like objects.")
+ "Additional text blocks to add to @file{.bash_profile}, which will be combined
+with text blocks from other extensions and the base service.")
(bashrc
(text-config '())
- "List of file-like objects.")
+ "Additional text blocks to add to @file{.bashrc}, which will be combined
+with text blocks from other extensions and the base service.")
(bash-logout
(text-config '())
- "List of file-like objects."))
+ "Additional text blocks to add to @file{.bash_logout}, which will be combined
+with text blocks from other extensions and the base service."))
(define (home-bash-extensions original-config extension-configs)
(match original-config
@@ -646,10 +657,16 @@ (define (generate-home-shell-profile-documentation)
'home-shell-profile-configuration))
(define (generate-home-bash-documentation)
- (generate-documentation
- `((home-bash-configuration
- ,home-bash-configuration-fields))
- 'home-bash-configuration))
+ (string-append
+ (generate-documentation
+ `((home-bash-configuration
+ ,home-bash-configuration-fields))
+ 'home-bash-configuration)
+ "\n\n"
+ (generate-documentation
+ `((home-bash-extension
+ ,home-bash-extension-fields))
+ 'home-bash-extension)))
(define (generate-home-zsh-documentation)
(generate-documentation
--
2.33.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH v3 2/2] doc: Improve documentation of the Bash home service
2021-11-07 11:36 ` [bug#51543] [PATCH v3 2/2] doc: Improve documentation of the Bash home service Xinglu Chen
@ 2021-11-07 20:18 ` Liliana Marie Prikler
0 siblings, 0 replies; 18+ messages in thread
From: Liliana Marie Prikler @ 2021-11-07 20:18 UTC (permalink / raw)
To: Xinglu Chen, 51543
Am Sonntag, den 07.11.2021, 12:36 +0100 schrieb Xinglu Chen:
> * doc/guix.texi (Shells Home Services): Document ‘home-bash-
> extension’
> configuration record.
> * gnu/home/services/shells.scm (generate-home-bash-documentation):
> Extract
> docstrings from ‘home-bash-extension’.
> (home-bash-configuration): Expound on docstrings.
> (home-bash-extension): Likewise.
>
> Fixes: <https://issues.guix.gnu.org/50991>
The docstrings LGTM now. This series is probably safe to go to master,
though you might want to wait for people to complain about the addition
of a field possibly breaking ABI and what not :P
Cheers
^ permalink raw reply [flat|nested] 18+ messages in thread
* bug#51543: [PATCH 0/2] Some improvements to the Bash home service
2021-11-07 11:36 ` [bug#51543] [PATCH v3 0/2] Some improvements to " Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 2/2] doc: Improve documentation of the Bash home service Xinglu Chen
@ 2021-11-07 20:58 ` Ludovic Courtès
2021-11-13 20:35 ` [bug#51543] " Ludovic Courtès
3 siblings, 0 replies; 18+ messages in thread
From: Ludovic Courtès @ 2021-11-07 20:58 UTC (permalink / raw)
To: Xinglu Chen; +Cc: 51543-done, Liliana Marie Prikler
Hello,
Xinglu Chen <public@yoctocell.xyz> skribis:
> home: services: bash: Add ‘aliases’ field.
> doc: Improve documentation of the Bash home service
Applied, thanks!
Liliana Marie Prikler <liliana.prikler@gmail.com> skribis:
> The docstrings LGTM now. This series is probably safe to go to master,
> though you might want to wait for people to complain about the addition
> of a field possibly breaking ABI and what not :P
Users won’t see any ABI breakage so I think we’re fine. Applied!
Thanks Xinglu & Liliana!
Ludo’.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [bug#51543] [PATCH 0/2] Some improvements to the Bash home service
2021-11-07 11:36 ` [bug#51543] [PATCH v3 0/2] Some improvements to " Xinglu Chen
` (2 preceding siblings ...)
2021-11-07 20:58 ` bug#51543: [PATCH 0/2] Some improvements to " Ludovic Courtès
@ 2021-11-13 20:35 ` Ludovic Courtès
3 siblings, 0 replies; 18+ messages in thread
From: Ludovic Courtès @ 2021-11-13 20:35 UTC (permalink / raw)
To: Xinglu Chen; +Cc: Liliana Marie Prikler, 51543
Hi!
Xinglu Chen <public@yoctocell.xyz> skribis:
> home: services: bash: Add ‘aliases’ field.
> doc: Improve documentation of the Bash home service
I had overlooked it but it breaks tests/guix-home.sh and
tests/home-import.scm. Could you take a look and send a patch in a new
issue?
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2021-11-13 20:37 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-01 9:43 [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
2021-11-01 9:45 ` [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
2021-11-01 9:45 ` [bug#51543] [PATCH 2/2] doc: Document ‘home-bash-extension’ configuration record Xinglu Chen
2021-11-01 10:45 ` Liliana Marie Prikler
2021-11-01 13:22 ` Xinglu Chen
2021-11-01 16:38 ` Liliana Marie Prikler
2021-11-05 11:56 ` Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 0/2] Some improvements to the Bash home service Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
2021-11-05 14:03 ` [bug#51543] [PATCH 2/2] doc: Improve documentation of the Bash home service Xinglu Chen
2021-11-05 19:36 ` Liliana Marie Prikler
2021-11-07 11:20 ` Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 0/2] Some improvements to " Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 1/2] home: services: bash: Add ‘aliases’ field Xinglu Chen
2021-11-07 11:36 ` [bug#51543] [PATCH v3 2/2] doc: Improve documentation of the Bash home service Xinglu Chen
2021-11-07 20:18 ` Liliana Marie Prikler
2021-11-07 20:58 ` bug#51543: [PATCH 0/2] Some improvements to " Ludovic Courtès
2021-11-13 20:35 ` [bug#51543] " Ludovic Courtès
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).