Konsole - Finally, a fun question

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.

So, where is the configuration file for Konsole?

Bart

konsole’s main config file: ~/.config/konsolerc
konsole’s profiles: ~/.local/share/konsole/profile-name.profile

AFAIK they are the only konsole related configuration files.

Don’t know how I missed them, but I did! :shame:

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.

Thanks for the pointer though.

Bart

When you want to change your prompt, you can put the command(s) in ~/.profile

The environment variables that decide how the prompts look are PS1 and PS2 (there are also PS3 and PS4, but I doubt that bothers you). So look in

man bash

browse through it searching for PS1 and you will find a lot of information. In particular look into the section PROMPTING. A lot to read there. :wink:

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:

henk@boven:~> echo $PS1
\$(ppwd)\]\u@\h:\w>
henk@boven:~> echo $PS2
>
henk@boven:~>

And, as I know the root password, I can also show you what they are for root:

boven:~ # echo $PS1
\$(ppwd)\]\\]\h:\w #\\]
boven:~ # echo $PS2
>

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.

This should be fun! Thanks for the instructions!

Bart

That was fun!

Create the file: /etc/bash.bashrc.local
Enter this:

if test "$UID" -eq 1000; then
    PS1="\e[0;33m\[$(ppwd)\]\u@\h:\w> \em"
fi

Save the file.
That’s it! Nothing more.

The prompt still turns red when I’m root and back to brown when I’m bart.
Now, we’ll see how long before a change is made to screw it up! :wink:

Thanks!

Bart

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

 $UID -eq 1000 ]] && PS1="\e[0;33m\[$(ppwd)\]\u@\h:\w> \e[m"

But of course adding to my .bashrc

PS1="\e[0;33m\[$(ppwd)\]\u@\h:\w> \em"

gives the same result (and I did this of course as user 1000, no need to wake up the system manager to do this as root).

1 Like

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.

Thanks for your reply! Appreciate it!

Bart

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.