GNU bug report logs - #70164
home-bash-service default PS1 overwrites .bashrc PS1 in login shells

Previous Next

Package: guix;

Reported by: Richard Sent <richard <at> freakingpenguin.com>

Date: Wed, 3 Apr 2024 15:54:03 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#70164: closed (home-bash-service default PS1 overwrites
 .bashrc PS1 in login shells)
Date: Mon, 29 Apr 2024 21:55:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Mon, 29 Apr 2024 23:53:54 +0200
with message-id <87mspbzvgt.fsf <at> gnu.org>
and subject line Re: [bug#70205] [PATCH] home: services: bash: Move default PS1 prompt to bashrc
has caused the debbugs.gnu.org bug report #70164,
regarding home-bash-service default PS1 overwrites .bashrc PS1 in login shells
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
70164: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=70164
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Richard Sent <richard <at> freakingpenguin.com>
To: bug-guix <at> gnu.org
Subject: home-bash-service default PS1 overwrites .bashrc PS1 in login shells
Date: Wed, 03 Apr 2024 11:52:47 -0400
Hi Guix!

A common convention for where to set PS1 is in .bashrc, not
.bash_profile [1-3]. Unfortunately home-bash-service doesn't support this
convention for login shells.

home-bash-service generates a default .bash_profile that follows these
steps:

1. Source .profile
2. Source .bashrc
3. Set PS1 if guix-defaults? is truthy

This means that any PS1 configuration in .bashrc is overwritten by
.bash_profile for login shells specifically.

This is visible in a TTY, but also in WSL, which defaults to opening a
login shell. PS1 will be Guix's predefined value instead of the value
set in .bashrc.

Setting guix-defaults? to #f has many side effects, so I don't feel that
is a valid solution.

A comment in home/serivces/shells.scm suggests setting PS1 via
environment-variables since that is appended to the end of
.bash_profile. This is fine for simple prompts, but complicated prompts
are often split apart into separate bash functions and variables. Either
an implicit dependency between .bashrc and .bash_profile is created, or
.bash_profile balloons into a mega-file while the conventional wisdom is
to keep it as simple as possible.

environment-variables also exports PS1, causing it to become an
environment variable, not a shell variable. This might cause some odd
behavior when subprocesses inherit it. [4]

Some possible solutions:

1. Move default PS1 to bashrc, right after serializing %default-bashrc
2. Keep default PS1 in .bash_profile, but before loading .bashrc
3. Add a set-prompt? field to home-bash-configuration

Of the 3, I think 1 is the best and plan to submit a patch for it soon.
I'm opening the bug in case anyone thinks I missed something.

[1] https://unix.stackexchange.com/a/549075
[2] https://superuser.com/a/789465
[3] https://superuser.com/a/789454
[4] https://unix.stackexchange.com/a/44000

-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.


[Message part 3 (message/rfc822, inline)]
From: Ludovic Courtès <ludo <at> gnu.org>
To: Richard Sent <richard <at> freakingpenguin.com>
Cc: 70205-done <at> debbugs.gnu.org, paren <at> disroot.org,
 Tanguy Le Carrour <tanguy <at> bioneland.org>, Andrew Tropin <andrew <at> trop.in>,
 70164-done <at> debbugs.gnu.org
Subject: Re: [bug#70205] [PATCH] home: services: bash: Move default PS1
 prompt to bashrc
Date: Mon, 29 Apr 2024 23:53:54 +0200
[Message part 4 (text/plain, inline)]
Hi Richard,

Richard Sent <richard <at> freakingpenguin.com> skribis:

> Reported in <https://issues.guix.gnu.org/70164>.
>
> * home/services/shells.scm (add-bash-configuration): Move default PS1 prompt
> from .bash_profile to .bashrc.
>
> Change-Id: Ic437458ee362cc4aa803a71c9962af866749f59a

Sounds reasonable to me; thanks for the clear explanation in
<https://issues.guix.gnu.org/70164>.

There was one missing newline before aliases so I made the following
change (adding two newlines, for good measure).

Applied, thanks!

Ludo’.

[Message part 5 (text/x-patch, inline)]
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index a5b2586dde..ee6b09f17c 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -421,11 +421,11 @@ (define (add-bash-configuration config)
      ,@(list (file-if-not-empty
               'bashrc
               (if (home-bash-configuration-guix-defaults? config)
-                  (list (plain-file-content %default-bashrc)
+                  (list (plain-file-content %default-bashrc) "\n"
                         ;; The host distro might provide a bad 'PS1'
                         ;; default--e.g., not taking $GUIX_ENVIRONMENT into
                         ;; account.  Provide a good default here when asked.
-                        "PS1='\\u@\\h \\w${GUIX_ENVIRONMENT:+ [env]}\\$ '"
+                        "PS1='\\u@\\h \\w${GUIX_ENVIRONMENT:+ [env]}\\$ '\n"
                         (serialize-field 'aliases))
                   (list (serialize-field 'aliases))))
              (file-if-not-empty 'bash-logout)))))

This bug report was last modified 1 year and 20 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.