Customizing Your Bash Prompt
Tags: bash, linux, customization, beginners
Published: 2023-05-03 03:25:55

In Linux most of the work I do happens in a command prompt. Many people don’t really care but looking at the same bash prompt everyday was really boring to me. One day when I was pair programming with one of my peers in college I realized that their bash prompt was customized. Different font colors, special characters and even an emoji! I missed an opportunity to ask my pair programming buddy how he did that so I did some research and found out that the bash terminal can be customized in many ways! I am going to show you how to do it yourself by using my prompt as an example. Here is what mine looks like!

![My Shell Prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t01xyxudty4fhdd9k61s.png)

For this to work we have to change the value of the PS1 environment variable. By doing this we can change the command prompt appearance and environment. To demonstrate type this into your terminal.

```bash
$ PS1="Hello Prompt "
```

You will see that your prompt is now Hello Prompt.

![Hello Prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mepoa4xgq1vrjn1iphha.png)

If you open up a new terminal you will notice that your changes didn’t persist. So if we want these changes to stay the same we have to add a line with your PS1 variable to the “.bashrc” file in your home folder. If you are on Mac you have to add that line to “.bash\_profile”.

### Special Characters

To add dynamic information we can use sets of special characters. Here are some of the most common ones.

*   `\d -`Current date
*   `\e` - Escape character
*   `\h` - Hostname
*   `\n` - Newline
*   `\t` - Current time 24-hour HH:MM:SS
*   `\T` - 12-hour HH:MM:SS
*   `\@` - 12-hour HH:MM am/pm
*   `\u` - Username of current user
*   `\w` - Path to current working directory

You are not limited to only these options though. There is a more detailed list of options you can use in the [Bash Manual](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Controlling-the-Prompt). So to start off with my example we would type this.

```bash
PS1="\\u@\\h: \\W\\$"
```


![Customized Prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pi9s36a87qie6mzd5y37.png)

### Colors

Special characters are simple to understand. Now we move on to colors. This syntax looks very ugly and messy so you will have to double check that you typed the right thing before you save it. These are the options for the common colors.

*   Black: \\033\[30m
*   Blue: \\033\[34m
*   Cyan: \\033\[36m
*   Green: \\033\[32m
*   Magenta: \\033\[35m
*   Red: \\033\[31m
*   White: \\033\[37m start of sequence
*   Yellow: \\033\[33m

We also need to wrap the following escape sequences around our color codes.

*   `\[`
*   `**\]**`

For more information on colors you can take a look at this [page](https://misc.flogisoft.com/bash/tip_colors_and_formatting).

Let’s implement some color to make the prompt look even fancier.

```bash
PS1="\\\[\\033\[35m\\\]\\u@\\h: \\W\\$ \\n\\\[\\033\[36m\\\]"
```


![Colorized Prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8tan9ndzd88h368fa1p.png)

### Emoji!

Now for the cherry on top we are going to add an emoji! I chose to add the snowman. Adding this is very easy. All you have to do is open up the emoji picker and copy and paste whatever emoji you want. On Linux press “Super key + .” or “Control + Command + Space” on Mac. In the end my PS1 variable looks like this.

```bash
PS1="\\\[\\033\[35m\\\]\\u@\\h: \\W\\$ \\n\\\[\\033\[36m\\\]// ⛄"
```


![Customization Completed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fcdgye7wq9r0p1mu82qv.png)

That is all. This might not be a tip that makes you more productive but it will sure give your work environment a personal touch. You will be happy looking at your very own personalized Bash prompt. I had a lot of fun messing with many of the options and special characters. Enjoy customizing your prompt and happy coding! 😎