Colorize Bash Console Color
Solution 1
Here /sys/module/vt/parameters
are three files:
default_blu
default_grn
default_red
Yellow is green and red. If you want to "boost" the normal color yellow (which you may have as brown), change the color with index three (the fourth slot) - set it to 255
in the green and red files.
Then, echo -n '\033]R'; tput setaf 3; echo hi
and you should get yellow.
For me, it seems this is already the color for bright yellow, in which case you'd use: tput bold; tput setaf 3; echo hi
.
If you need to setup the prompt differently in the console and in X, in your .rc
file, before you set PS1
, find out if you are in the console or in X. Set the color accordingly.
Solution 2
Usually you should use ncurses library to use terminal features.
In your case you can use highlight on:
PS1="[\033[33;1m][\u@\h \W]$ [$Color_Off]"
Related videos on Youtube
Brad
Updated on September 18, 2022Comments
-
Brad almost 2 years
I need to be able to set my CentOS 6.4 bash prompt color to yellow.
I've managed to find where to set this (.bashrc) and the ANSI color for yellow (\e[0;33m).
I've setup my prompt as follows: PS1="[\033[33m][\u@\h \W]$ [$Color_Off]"
This all works fine when I ssh into our a system BUT when I use the local console it comes out as BROWN.
How can I modify bashrc so that its yellow regardless of weather I use SSH or the local console?
Please don't suggest I use a different color - for various reasons it would be a significant amount of effort to use a different color.
See the following for what I mean:
-
Amitav Pajni about 11 yearsThat's the normal color for the local console. Sorry.
-
-
jumeno about 11 yearsStill brown at the console - yellow through SSH.
-
Brad about 11 yearsThis server doesn't have a GUI - so there's no right click option. As far as changing the colors in Putty - I'm aware that can be done but I want the color right from the start. There are many people that connect to this system and its not practical to ask them all to modify their SSH application to display the correct color. Thanks though.
-
Brad about 11 yearsIn /sys/module/vt/parameters/default_red I have: 0,170,0,170,0,170,0,170,85,255,85,255,85,255,85,255 In /sys/module/vt/parameters/default_grn I have: 0,0,170,85,0,0,170,170,85,85,255,255,85,85,255,255 I'm not exactly sure what I need to change - what do you mean by index three/fourth slot?
-
Brad about 11 yearsBy the way I ran the commands you suggested above. The text is still orange/brown. See the following screenshot: picpaste.com/4-30-2013_8-23-37_AM-ODRQImBd.jpg
-
Pascail about 11 yearsAdded a source in Berg's answer that describes how to set numbers in /sys/module/... files. I learned something thanks to you :)
-
Emanuel Berg about 11 years@Brad: Yes, you need to change the fourth (4th) digit to
255
(or any digit higher than what you have now:170
and85
) for red and green to make it brighter. The first digit has index 0, so the fourth digit has index 3. This is why, when you use this color, you usetput setaf 3
(and not4
).