Making Colored Bash Prompts | Easier said than done.

For the past few days I've been working on my bash prompt. I found it to be very confusing so I thought I would share it for my first day in #100DaysToOffload.

my bash prompt, perfectly bisexual.

For the past few days I've been working on making my bash prompt look like the bisexual flag. It wasn't so easy partly because there aren't many colors to chose from, partly because it's not very intuitive.

Let's look at a basic uncolored prompt.

[user@linux-box ~]$ _

the code behind it would be this:

PS1='[\u@\h \w]\$ '

(the \u means the user, the \h means the hostname, \w means the working directory and \$ is just the dollar sign escape character.)

If you put that in your ~/.bashrc, your prompt will be uncolored. I like having color on my bash prompt because I can run long commands and glance at my screen for colour (when the command is done.)

For colour you will have to put the colour code. Here is an example of one:

\[\033[95m\]

That code is magenta. To change the color you will have to change the number followed by the m.

In this Unix exchange thread, you will use the number and replace the 95 in the example code, then paste it into your PS1 line.

Here is mine currently:

PS1='[\[\033[95m\]\u\[\033[90m\]@\[\033[94m\]\h \w\[\033[37m\]]\$ '

It starts with a [, then changes the color to magenta, then my username, then change the colour to grey, then the @ symbol, then changes the color to blue, then the hostname, working directory then it changes the color back to white. then it ends with the ] and the dollar prompt.