Linux and Open Source

Personalizing your bash prompt

Based on my last blog entry, I thought I would give you some tips on personalizing your bash prompt. I’ve been doing this for a long, long time and I find it makes using your terminal more simple and a bit more fun.

Let’s create a yellow prompt that says URHERE:. To do this do this we will be using some different characters (and combinations therein) not used in a standard prompt. All of the below will be written within your ~/.bashrc file.

The command to get this new, unique prompt looks like:

PS1=’\[\033[1;33m\]URHERE: \w \[\033[0m\] ‘

What does this mean? Let’s tear it apart and find out. The first sequence, `\[033[1;33m\] does the following:

  • ‘ - begin the string
  • \[ - begin a string of non-printing characters
  • \ - escape character preserving the literal value of the next character(s)
  • 033 - ascii code for the escape key
  • [ - used to separate the sequences
  • 1;33m - defines the color yellow
  • \w - adds the full path to the current working directory
  • \] - ends the string of non-printing characters

The next section, URHERE:, prints our message URHERE followed by the : symbol and a space for clarity. The final section, \[033[0m\]‘, ends our prompt with the following:

  • \] - begin a string of non-printing characters
  • \ - escape character preserving the literal value of the next character(s)
  • 033 - ascii code for the escape key
  • [ - used to separate the sequences
  • 0m - ends the color definition
  • \] - ends the string of non-printing characters

And there you have it. Of course you can customize this even further by changing colors or (of course) printed messages. To change the colors you will use the following strings:

  • 1;37m White
  • 37m Light Gray
  • 1;30m Gray
  • 30m Black
  • 31m Red
  • 1;31m Light Red
  • 32m Green
  • 1;32m Light Green
  • 33m Brown
  • 1;33m Yellow
  • 34m Blue
  • 1;34m Light Blue
  • 35m Purple
  • 1;35m Pink
  • 36m Cyan
  • 1;36m Light Cyan

Are you a bash junkie?

One area I find color useful is to define various machines and their purposes. When logged into more than one machine I like to be able to tell which machine I’m working with (before I run the one command, on the wrong machine, that could bring down the entire network.) Because of this, I will chose a color scheme such as:

  • Blue = mail server
  • Yellow = ftp server
  • Red = firewall
  • Green = Workstation

That way I always know which machine I’m about to send a command to.

Do you have your own personal bash prompt configurations? Let us know in the comments below.

Get IT Tips, news, and reviews delivered directly to your inbox by subscribing to TechRepublic’s free newsletters.

Jack Wallen

About Jack Wallen

A writer for over 12 years, Jack's primary focus is on the Linux operating system and its effects on the open source and non-open source communities.

Jack Wallen

Jack Wallen

Jack Wallen is an award-winning writer for Techrepublic and Linux.com. As an avid promoter/user of the Linux OS, Jack tries to convert as many users to open source as possible. His current favorite flavor of Linux is Bodhi Linux (a melding of Ubuntu and Enlightenment).

When Jack isn't writing about Linux he is hard at work on his other writing career -- writing about zombies, various killers, super heroes, and just about everything else he can manipulate between the folds of reality. You can find Jack's books on Amazon, Barnes & Noble, and Smashwords.

Outnumbered in his house one male to two females and three humans to six felines, Jack maintains his sanity by riding his mountain bike and working on his next books. For more news about Jack Wallen, visit his website Get Jack'd.

2
Comments

Join the conversation!

Follow via:
RSS
Email Alert