Fedora 39 bash prompt now displays exit codes

Hi Folks,

Updated to Fedora 39 today. Opened an xterm (then a console). Ctrl-C (termination) of a process results in the exit code (130) being displayed in red with the next command prompt. A little more experimentation showed that it was indeed the exit code (like trying to ls a non-existent file returned another code).

Perhaps for some folks this is a feature.

I removed this feature by editing /etc/profile.d/bash-color-prompt.sh as follows:
Original:
PS1='\[\e[${PROMPT_COLOR:-32}m\]\u@\h\[\e[0m\]:\[\e[${PROMPT_COLOR:-32}m\]\w\[\e[0;31m\]${?#0}\[\e[0m\]\$ '

Edited:
PS1='\[\e[${PROMPT_COLOR:-32}m\]\u@\h\[\e[0m\]:\[\e[${PROMPT_COLOR:-32}m\]\w\[\e[0m\]\$ '
The difference:
\[\e[0;31m\]${?#0}
removed near end of PS1 definition.
Not claiming expert solution, but this worked for me.

Warning: do NOT try to modify /etc/bashrc

If someone has another more elegant solution, pray do tell.

Cheers,

Chris

1 Like

It’s also possible to completely disable the new prompt by uninstalling bash-color-prompt.

rpm-ostree users can delete /etc/profile.d/bash-color-prompt.sh. The original file remains in /usr/etc if you ever want to restore it.

4 Likes

I sorta like the colored prompt, so I kept it (but hated the termination code :slight_smile: ).

Regardless, thanks, Chris!

Cheers,

Chris

1 Like

Well I don’t love it either, but I put/left it in as “better than nothing”: failures are not always obvious.

If someone can make it work better that would be great.

Admittedly we have managed okay without this “feature” for a long time, so perhaps it is not strictly needed: you can also open a bug if you wish. It can be made optional I think: (edit) I went ahead and pushed an update to rawhide just now.

It has been possible from the beginning for users to have colored prompts, but does require editing of /etc/bashrc or ~/.bashrc to achieve that and setting the value of PS1 appropriately.

This change seems to make the colored prompts easier for the average user and simply needs to be tweaked to be suitable.

I might note that a color that works perfectly with a white background may not be suitable for a dark background, and vice-versa. Thus what works for a user who uses a dark theme might not work for those who use the light theme. Maybe that needs considered in setting the prompt colors as well.

It also has historically been appropriate for the user prompt to be one neutral color – green, blue, yellow – and if logged in as the root user the prompt has often been red to reflect the difference in potential risks and a reminder that the user is operating in a special mode.

I find that these are the settings that work best for me in both light and dark mode for both my regular user and for the root user.
Regular user

$ echo $PS1
\[\033[01;32m\][\u@\h\[\033[01;33m\] \W\[\033[01;32m\]]$\[\033[00m\]

For the root user

# echo $PS1
\[\033[01;31m\][\u@\h\[\033[01;36m\] \W\[\033[01;31m\]]#\[\033[00m\]

This is achieved in /etc/bashrc with:
(and works in both a standard terminal as well as a terminal window.)

# If id command returns zero, you are the root user.
if [ $(id -u) -eq 0 ];
then # you are root, set red colour prompt
  PS1="\[\033[01;31m\][\u@\h\[\033[01;36m\] \W\[\033[01;31m\]]#\[\033[00m\] "
else # normal user
  PS1="\[\033[01;32m\][\u@\h\[\033[01;33m\] \W\[\033[01;32m\]]\$\[\033[00m\] "
fi

I think the request here is not about the colored bash prompt it selves, it is about the colored exit codes it displays on new F39 installs.

On upgraded Fedora installations you can not see it.

Save for me. I manually reverted back to the previous PS1 style using the same method.

It should be fixed in the next version

commit 0643778d983a4d98d937bc76756cf05852169d2a (HEAD -> rawhide, origin/rawhide, origin/main, origin/HEAD)
Author: Jens Petersen <petersen@redhat.com>
Date:   Thu Nov 9 17:45:14 2023 +0800

    only show error code if PROMPT_ERROR set

2 Likes

Yes https://bodhi.fedoraproject.org/updates/FEDORA-2023-3e862eb724
is the F39 update which turns off the display of exit codes,
which should be in updates-testing tomorrow hopefully -
also with some new features :slight_smile:
Notably the color of current dir can now be set separately.

The developer himself. Nice to see you.

1 Like