Skip to content
Fragmented Development

My personal bash prompt

Over years of using bash, I've customized my prompt configuration to fit my preferences. I value a minimal appearance, and I prefer to convey information with colors when possible. I also like it if information is hidden until relevant.

If that sounds like fun to you, you're in luck! Here's how I've done it. You can even get my latest .bashrc file if you'd like.

Basic bash prompt information

The main file involved in your bash prompt is the bash configuration file, .bashrc. This file is located in your home directory.

Inside the .bashrc file, there are three variables that affect your prompt:


Bash allows you to set colors using escape sequences - special codes that are escaped by surrounding them with square brackets.

Bash prompts have several unique problems with colors and escape sequences. If you don't escape your color sequences at the right time, they can be escaped multiple times, which can wreak havoc with your terminal.

In addition, escape sequences are a little bit cryptic to look at. For instance, the escape sequence "\E[37;44m" apparently colors your text white, and sets the background color to blue, according to's "colorizing scripts" tutorial.

To avoid all that, I use the tput utility, I assign it directly to the PS1 variable, and only escape it at the last moment.

Embedding code

If you want your bash prompt to change based on different criteria, you can embed bash scripting into the variable with single quotes.

If you use single quotes, the text is only evaluated when your prompt is printed to the terminal. So, `PS1='$( date )' will make your prompt the date and time when the prompt was printed, and will be updated each printing.

I use embedded scripting to change the colors of different parts of my prompt, and add text in certain circumstances. For instance, if my current user has system mail in /var/mail/[USER], my username is turned red and bold. When I delete that mail, it show up as orange again.

My Prompt

Here's an example of my prompt, and how I use colors and extra text to indicate important information about my system and my environment.

An example of my bash prompt, in a 'clean' state and a 'messy' state.

Tags: linux

Add Your Comment