I use Konsole quite a bit. I have created a personal profile (old style green on black) am am pleased with it. When I su - to do some things, my prompt turns red denoting I’m root. Really nice! Besides reminding me of whoami, it makes it a lot easier to separate the returns from a process from my entry. I would like to change the color of my regular user so I don’t get as lost in the stuff on the screen.
It seems Konsole is calling bash, so I looked in all over my drive for a conf file that seemed to change $PS1 when becoming root and can’t find one.
I found the area in /etc/bash.bashrc but right at the top of the file is a warning to not change anything as it might get overwritten during an update. I guess I could make a backup copy of this file, make the changes and comment the section where they are, make another copy and then, if my changes go away, I’ll know where to put them back in.
Oh, and about your assumption “It seems Konsole is calling bash”, the icon “Konsole” does start a konsole with bash as the program running inside it. But every character based program (using stdin and stdout/stderr) can be run there. So it is up to you (as almost everything inside Unix/Linux). It is either a default of konsole, or stated as such in what the icon executes.
And when a shell, or in the case of Linux most often bash, is run inside konsole (which itself is only a terminal emulator), then you will get what the shell presents you. And to show that it is your turn to type something, it shows a prompt. And that is the prompt you talk about and the configuration of which I pointed to above.
This prompt is thus NOT connected and thus NOT configured in any konsole configuration. It is purely shell. I did not change from the default my bash is installed with and I have:
In the bash man page PROMPTING section, you can find:
begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
]
end a sequence of non-printing characters
So there are non printing characters send to the terminal (konsole), which the terminal then can interpret. The terminal in this case is assumed to be a ANSI terminal (often called VT100 or VT125 terminal after the implementation of the ANSI standard in their “glass TTYs” by DEC) and the non printing sequences are also known as Esc sequences and I have no doubt (though I did not check until the last byte) that there are Esc sequences in the root prompt to print into red send to the terminal.
You need to create the file ‘/etc/bash.bashrc.local’ and, put your changes in there …
But, you need to occasionally check for structural changes in ‘/etc/bash.bashrc’ and, occasionally, change your local changes to match up with the latest “bash.bashrc” style and structure.
Well, I doubt it was the idea of the designers that one configures the wishes of an individual user in the general system wide configuration with an ‘if’ statement.
An individual user configures such things in his own configuration file (like ~/.bashrc). No at least because each individual user has access to these files in her/his home directory and not to files in /etc.
So your idea of doing this your way would result in an lot of these “$UID” -eq 1000, 1001, 1002, etc.to be managed by root (on request of the users) instead of letting each user manage when they want and as they want.
BTW, feel free to use your programming style as you want to do, but I would write
And one more aspect that seems to be of importance to you, having fear that a configuration file might become overwritten by a package install/update: the files of a user in his home directory (like ~/.bashrc) will never become overwritten by such an action.
Point taken! You are, of course, quite correct.
In my defense though, it was 4 AM when my little gem was created.
Your thoughts though, on the programming style (And this goes way, way back), Which way, yours or mine, uses fewer cpu cycles?
I like your version as it’s one line, and I’ll probably change my version, but I can remember doing speed testing on whether case statements or if statements were faster. This was back with 4.7 Mh cpus.
As I explained, it is very personal and about programming style. I think your version is OK, but I would never use ‘test", that is really old-fashioned. You could of course use ‘’ (basic Bourne shell), but I prefer ‘’ writing my larger scripts in ksh (and it being retrofitted in bash to my joy). And yes, for one liners, I prefer the "&&’ and ‘||’, but again that is personal preference.
I only wanted to show alternatives because seeing them makes one more affluent in writing and understanding shell commands/scripts.
But what I find really important is the message that one should adapt one’s prompt in one’s own configuration file: ~/.bashrc. And not letting root do so in the general /etc/.bashrc with a test to restrict it to that one user. IMHO that points to a complete misunderstanding about system configuration vs. user configuration. Which may even point to not understanding the multi-user concept of Unix/Linux. And that concept is so important for understanding many things in Unix/Linux.