Bug 503304 - RFE: add tty to PS1 prompt in /etc/bashrc
RFE: add tty to PS1 prompt in /etc/bashrc
Product: Fedora
Classification: Fedora
Component: setup (Show other bugs)
All Linux
low Severity medium
: ---
: ---
Assigned To: Ondrej Vasik
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2009-05-31 02:53 EDT by Gerry Reno
Modified: 2009-06-29 09:56 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-06-29 09:56:04 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Gerry Reno 2009-05-31 02:53:24 EDT
Description of problem:
Something that I have found very useful is adding the tty to the PS1 prompt in /etc/bashrc.  With the increased usage of virtual machines and subsequent use of many console windows it is very essential to know at a glance the tty of a particular console window without the need to apply focus to the window and then focus to the particular terminal and then issuing some command to determine the tty.  
Adding '\l' to the PS1 prompt in /etc/bashrc provides this information like so:
PS1="[\u@\h:\l \W]\\$ "
And this produces a prompt like this:
[greno@myhost:tty2 ~]$  (consoles)
[greno@myhost:2 ~]$     (terminal windows: pseudo-terminal)

This small addition has proven very useful and timesaving.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
Actual results:

Expected results:

Additional info:
Comment 1 Ondrej Vasik 2009-06-01 10:27:39 EDT
Thanks for suggestion. However, I tend to close that RFE as wontfix. Change like this would confuse many users - as everyone will see tty in his prompt. There is of course increased usage of virtual machines and having tty in prompt might be very useful and timesaving in such case, but I doubt that usecase is major at the moment. You could always override default global PS1 settings for specific user with ~/.bashrc . 

I don't know about any major Linux distribution with tty in PS1 as default ( I checked Debian,Ubuntu,Gentoo and OpenSuSe). Having this Fedora specific without wider consensus (e.g. discussion on fedora-devel-list@redhat.com or some other relevant mailing list) is no-way for me. 

Maybe few commented-out examples of PS1 prompt with description could be added into /etc/bashrc to let root of the machine choose which one he prefers. Feel free to add your comments if you have different idea how to solve it (without having it default for everyone)...
Comment 2 Gerry Reno 2009-06-01 11:33:07 EDT
I started out by changing PS1 in individual ~/.bashrc but then quickly found out that it was a lot of work to keep adding this for various users so then I moved it to /etc/bashrc which worked a lot better.  Of course all users pick it up then.

Maybe if there was some flag (env var) that would drive /etc/bashrc as to whether to include the tty in the prompt.  PS1DISPLAYTTY ?

I don't think the tty would confuse users other than complete novices.  And it is a good thing that they need to know about anyway.  So they learn something.
Comment 3 Ondrej Vasik 2009-06-02 07:17:16 EDT
If you are root on server and you want to change PS1 for all user then /etc/bashrc is definitely better way than changing ~/.bashrc for every user.  Having ennvar especially for this doesn't solve much - as you still have to define that value - and that's almost the same amount of work as editing /etc/bashrc directly. File /etc/bashrc is marked as config(noreplace), so changes will not get replaced after setup update. Additionally - PS1 envvar will not get replaced by /etc/bashrc if you set it different from bash default (PS1="\\s-\\v\\\$ ").

As you said - complete novices could be confused by such change. I have seen some tuned /etc/bashrc files with tty in prompt, sometimes they activated this prompt for non-TERM="xterm" sessions - so generally not for X. This should prevent confusion for the complete novices as they usually don't use other runlevels than 5. I'm still a bit reluctant to do that change without concensus (or without having that change in other major distro(s)) - to prevent as much diversity as possible in default envvar values between distributions.

Anyway adding some examples of useful PS1's styles into /etc/bashrc (including the one how to get tty into prompt) sounds as good compromise as bash manpage is quite long to read and such example could be used very quickly. Changing default value would mean another RFE for PS1(or other  improvement soon, as there are more generally useful things and we could easily end up with multiline prompt.
Comment 4 Gerry Reno 2009-06-02 11:03:02 EDT
It's good that /etc/bashrc is config(noreplace) but I was hoping to not have to change the default /etc/bashrc so that we do pickup new changes automatically without having to go through merging.  We've got too many merges already as it is when there are updates/installs.

Examples in /etc/bashrc would be nice but not a nice as having tty added to the PS1 by /etc/bashrc for consoles.

The terms in the guis appears to be 'xterm' and the console terms appear to be 'linux'.  So maybe consider doing this where term is not 'xterm'.  I cannot see where that would bother any novice as they don't work from consoles just terminals in the gui.  And that would satisfy both needs.
Comment 5 Ondrej Vasik 2009-06-29 09:56:04 EDT
I talked a bit with my colleagues about that bugzilla and they don't like the idea of changing PS1 defaults. Neither do I. Generally it turned out that even example is not good idea as any change to /etc/profile or /etc/bashrc causes need for merging future changes (if some system level default envvar will be added/changed). Therefore I added suggestion for usage of custom shell script included in /etc/profile.d/ - which will prevent need for merging and should make everyone happy (as you could easily add PS1 change there). 

Closing that bugzilla WONTFIX as I don't want to change defaults at the moment - but at least a hint for custom shell script with how to add tty into PS1 was added into /etc/bashrc. Thanks for suggestion anyway...

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