ThorneLabs

Customize Your BASH Prompt


TwistedCode has a fantastically detailed post about customizing your BASH prompt. I used the information there to create the following BASH prompt that I use across my local machine and servers.

Appearance

The BASH script below will create the following BASH prompt where the HH:MM:SS is red, user is green, hostname is yellow, and dir is blue:

[HH:MM:SS][user@hostname][dir]

BASH Script

Place the following in ~/.bash_profile to apply only to your user or in /etc/profile.d/colorprompt.sh to apply system wide:

# Custom PS1
RED='\[\e[0;31m\]'
LIGHTRED='\[\e[1;31m\]'
GREEN='\[\e[0;32m\]'
LIGHTGREEN='\[\e[1;32m\]'
BLUE='\[\e[0;34m\]'
LIGHTBLUE='\[\e[1;34m\]'
YELLOW='\[\e[1;33m\]'
PURPLE='\[\e[0;35m\]'
LIGHTPURPLE='\[\e[1;35m\]'
WHITE='\[\e[1;37m\]'
NORMAL='\[\e[0;37m\]'
CLEAR='\[\e[00m\]'

export PS1=''"${NORMAL}"'['"${RED}"'\t'"${NORMAL}"']['"${GREEN}"'\u'"${NORMAL}"'@'"${YELLOW}"'\h'"${NORMAL}"']['"${BLUE}"'\W'"${NORMAL}"']'"${CLEAR}"' '

If you found this post useful and would like to help support this site - and get something for yourself - sign up for any of the services listed below through the provided affiliate links. I will receive a referral payment from any of the services you sign-up for.

Get faster shipping and more with Amazon Prime: About to order something from Amazon but want to get more value out of the money you would normally pay for shipping? Sign-up for a free 30-day trial of Amazon Prime to get free two-day shipping, access to thousands of movies and TV shows, and more.

Thanks for reading and take care.