2015-09-15

Color coding your shell prompt

Someone asked me how to get colors into your bash shell prompt. Easy!

Add this your ".bashrc". Additionally I've added a text variable which could be used to show for example "OpenStack", "KVM" or similar to identify on which datacenter you are operating on.



# User specific aliases and functions
datacenter="[Red Hat]"
export PS1='\[\e[1;32m\]\u@\h:\w\e[1;31m${datacenter}\e[1;32m$\[\e[m\] '

Test by running: "source .bashrc"

The color codes are highlighted. Some example colors:
Black 0;30
Red 0;31
Green 0;32
Brown 0;33
Blue 0;34
Purple 0;35
Dark cyan 1;36

(0=bright, 1=dark color)

Your terminal should look something like this now:


No comments:

Post a Comment