Bug 2248853 - Colored prompt is not set for login shells
Summary: Colored prompt is not set for login shells
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: shell-color-prompt
Version: 39
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Jens Petersen
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-11-09 10:05 UTC by Sam Morris
Modified: 2023-11-20 02:22 UTC (History)
1 user (show)

Fixed In Version: shell-color-prompt-0.2-1.fc39 shell-color-prompt-0.2-1.fc37 shell-color-prompt-0.2-1.fc38 shell-color-prompt-0.2-1.el9
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-11-14 01:44:11 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
0001-Set-prompt-when-called-from-a-login-shell.patch (1.61 KB, patch)
2023-11-09 10:28 UTC, Sam Morris
no flags Details | Diff

Description Sam Morris 2023-11-09 10:05:02 UTC
When I SSH into a system where bash-color-prompt is installed I get the traditional monochrome prompt.

If I run 'bash -l' at this point, the shell is launched with a monochrome prompt.

Setting prompt_color_force in either .bash_profile or .bashrc has no affect.

Whereas running 'bash' launches a shell with a color prompt.

Reproducible: Always

Steps to Reproduce:
1. Install bash-color-prompt
2. SSH into machine
Actual Results:  
Prompt is not colored

Expected Results:  
Prompt should be colored

Adding some 'echo' commands to the top of the various initialization files reveales the order they are called:

  [sam@host ~]$ bash -l
  /etc/profile
  bash-color-prompt.sh
  /etc/bashrc
  .bash_profile
  .bashrc
  /etc/bashrc

So because this is a login shell, /etc/profile is sourced first. This goes on to source /etc/profile.d/bash-color-prompt.sh which checks that PS1 is set to its traditional Fedora default before enabling the color prompt.

But at this point, /etc/bashrc has not run yet, which is the compoment that changes PS1 to its traditional Fedora default; at the time /etc/profile runs, PS1 is still set to the bash default.

Here's the test in bash-color-prompt.sh:

  if [ "$PS1" = "[\u@\h \W]\\$ " -a "${TERM: -5}" = "color" -o -n "${prompt_color_force}" ]; then

And here's how /etc/bashrc sets PS1:

  [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "

The hacky way to fix this is to rewrite bash-color-prompt.sh's test as:

  if [ '(' "$PS1" = "[\u@\h \W]\\$ " -o "$PS1" = "\\s-\\v\\\$ " ')' -a "${TERM: -5}" = "color" -o -n "${prompt_color_force}" ]; then

i.e., checking that PS1 is either set to bash's default or Fedora's traditional default.

It would be better to set the color prompt directly in /etc/bashrc so that it's done consistently during the shell initialization process regardless of whether the shell is a login shell or not but that's a wider-scoped change.

Comment 1 Sam Morris 2023-11-09 10:28:43 UTC
Created attachment 1998060 [details]
0001-Set-prompt-when-called-from-a-login-shell.patch

Having some trouble getting an SSH key set up on Fedora Pagure so here's an old fashioned patch.

Comment 2 Jens Petersen 2023-11-10 06:31:57 UTC
Thanks for this. I will include it in coming 0.2.

Comment 3 Fedora Update System 2023-11-10 17:18:06 UTC
FEDORA-2023-3e862eb724 has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-3e862eb724

Comment 4 Jens Petersen 2023-11-10 17:18:40 UTC
This should be fixed in 0.2, which I built for F39 and F40 so far.

Comment 5 Sam Morris 2023-11-10 17:20:55 UTC
Thanks!

Comment 6 Fedora Update System 2023-11-11 02:24:06 UTC
FEDORA-2023-fb9fbe1bed has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2023-fb9fbe1bed

Comment 7 Fedora Update System 2023-11-11 02:31:02 UTC
FEDORA-2023-3e862eb724 has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-3e862eb724`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-3e862eb724

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 8 Fedora Update System 2023-11-11 06:03:42 UTC
FEDORA-2023-79d91fcab0 has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2023-79d91fcab0

Comment 9 Fedora Update System 2023-11-11 08:49:38 UTC
FEDORA-EPEL-2023-dc012e88bc has been submitted as an update to Fedora EPEL 9. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2023-dc012e88bc

Comment 10 Fedora Update System 2023-11-12 01:29:01 UTC
FEDORA-2023-fb9fbe1bed has been pushed to the Fedora 38 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-fb9fbe1bed`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-fb9fbe1bed

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 11 Fedora Update System 2023-11-12 02:23:40 UTC
FEDORA-EPEL-2023-dc012e88bc has been pushed to the Fedora EPEL 9 testing repository.

You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2023-dc012e88bc

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 12 Fedora Update System 2023-11-12 03:08:44 UTC
FEDORA-2023-79d91fcab0 has been pushed to the Fedora 37 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-79d91fcab0`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-79d91fcab0

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 13 Fedora Update System 2023-11-14 01:44:11 UTC
FEDORA-2023-3e862eb724 has been pushed to the Fedora 39 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 14 Fedora Update System 2023-11-20 00:51:00 UTC
FEDORA-2023-79d91fcab0 has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 15 Fedora Update System 2023-11-20 01:29:35 UTC
FEDORA-2023-fb9fbe1bed has been pushed to the Fedora 38 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 16 Fedora Update System 2023-11-20 02:22:25 UTC
FEDORA-EPEL-2023-dc012e88bc has been pushed to the Fedora EPEL 9 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.