Colored console (Bash)

From Rosalab Wiki
Revision as of 13:13, 27 August 2012 by Juliette (Talk | contribs)

Jump to: navigation, search
If you don't want to edit files manually, there is the console-gentoo-style package in contrib updates

When working in console, one can note that it is sometimes not easy to analyze output of different programs. Users can also claim about bad visual delimitation between prompt and text area. To solve this issues, we recommend to use colors to highlight console output.

Remember that in any system we have at least two users: 1 - the root one and 2 - normal user himself. For different users, you should edit different configuration files.

User console

In order to get a colored prompt in user's console, go to home folder, open the (hidden) .bashrc file and add the following lines there:

#PS1='[\u@\h \W]\$ '
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] '

Save the file, relaunch console and enjoy the colors:

Bash-color1.png

Root console

In order to get a colored prompt in root console, launch console under the root use, open the /root/.bashrc file and add the following lines there:

#PS1='[\u@\h \W]\$ '
PS1='\[\e[0;31m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] '

Save the file, relaunch console and enjoy the colors:

Bash-color2.png

About colors

Short list of colors used:

'\e[0;30m' - Black
'\e[0;31m' - Red
'\e[0;32m' - Green
'\e[0;33m' - Yellow
'\e[0;34m' - Blue
'\e[0;35m' - Purple
'\e[0;36m' - Turquoise
'\e[0;37m' - White