How to colorize bash prompt easily

Posted by Arkham on June 24th, 2009

lost_numbers_fan

Sometimes, the bash prompt can look a little dull and it may become difficult to recognize where the output of a command ends. Here I provide with a very simple way to customize your bash prompt by adding some colors.

First of all, add these colors definition to your .bashrc

## Fancy colors
red='\[\e[0;31m\]'
RED='\[\e[1;31m\]'
blue='\[\e[0;34m\]'
BLUE='\[\e[1;34m\]'
cyan='\[\e[0;36m\]'
CYAN='\[\e[1;36m\]'
black='\[\e[0;30m\]'
BLACK='\[\e[1;30m\]'
green='\[\e[0;32m\]'
GREEN='\[\e[1;32m\]'
yellow='\[\e[0;33m\]'
YELLOW='\[\e[1;33m\]'
magenta='\[\e[0;35m\]'
MAGENTA='\[\e[1;35m\]'
white='\[\e[0;37m\]'
WHITE='\[\e[1;37m\]'
NC='\[\e[0m\]' # No Color

The variables you want to use are

  • \u – username
  • \h – host name
  • \w – current absolute path
  • \W for current relative path
  • \$ – te prompt character (eg. ‘#’)

For example, my current setup looks like:

PS1="${green}\u${NC}@${green}\h ${BLUE}\w${NC} ${GREEN}\$ ${NC} "

Enjoy ;)

This entry was posted on Wednesday, June 24th, 2009 at 19:02 and is filed under computers. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Tags: , , ,

Comments are closed.