This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How can i change colour of the bash prompt in konsole?

Tags: None
(comma "," separated)
Nightmar3
Registered Member
Posts
1
Karma
0
airdrik
Registered Member
Posts
1854
Karma
5
OS
That depends on how exactly you want to change things.
You can change the overall color scheme of the text in konsole by right-clicking -> Edit Current Profile -> Appearance
Or you just want to change the appearance of the bash prompt, you can google "customize bash prompt" and find plenty of tutorials and resources.


airdrik, proud to be a member of KDE forums since 2008-Dec.
User avatar
thunder422
Registered Member
Posts
81
Karma
1
OS
Do you mean something like this:
Image
This was accomplished in bash by customizing the PS1 environment variable in the ~/.bashrc configuration file, as follows:
Code: Select all
export PS1='\[\e[1;30m\]\u,\!\[\e[00m\]$(__git_ps1 ":\[\e[1;33m\]%s\[\e[00m\]"):\[\e[1;34m\]\w>\[\e[00m\] '
However, there is way more going on here then you need - it has the user name, the bash command history line number, current git repository branch name, and the current working directory.

The magic of changing colors is with escape sequences - the "\[\e[XXm\]" sequences - where XX=1;30 is for dark gray, XX=1;33 is for yellow, XX=1;34 is for light blue, and XX=00 resets the color to the default foreground. See details at http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html. Each of these need to be surrounded by by "\[" and "\]" for non-printing characters (i.e. color escape sequences).

There are other escape sequences for adding information like "\u" for the user name, "\!" for the command history number, and "\w" for the current working directory. The "$(__git_ps1 ..." is the output of a bash function loaded from the git prompt script, but can be any command or function. See all the bash escape sequences at http://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html - there are whole pile of them.


Currently running KDE Neon 5.22.5 and 5.19.4 (with Windows 10 in a VM); migrated from Linux Mint 17.3


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan, Sogou [Bot]