Ultimate Terminal Customization

mikgross

Mikael

Posted on June 22, 2020

Ultimate Terminal Customization

Introduction

If you are a Linux user, you will use your terminal a lot. Terminal, once you know how to navigate your machine with it and work on a daily basis, will tremendously increase your productivity. For example, you can easily move files around or use CLIs from your favorite providers or apps to perform complicated tasks that would take way more time if done through a visual interface. In summary, it allows you to have a greater understanding of how your machine works and lets you be more productive, at the cost of you staring at a black screen with cryptic messages.

Just type cmatrix in it for fun.

Anyway.. Since we are going to spend a lot of time in it doing various complex things and probably get frustrated over time, why not make it pretty and fun. For your own sanity of course.

In this very short tutorial I will show you how to easily customize your terminal. I am myself using Linux Ubuntu 19.10. Users from Mac and Linux distros should have a pretty similar experience. Microsoft users, I can do nothing for you.

Most Ubuntu users start with the terminal looking almost like this:
Alt Text

A completely fine looking terminal if you ask me. But not fancy enough for our special breed of dev. We want something personal so when our colleagues or friends look at our terminal, they understand that we know what we are doing.

Let's change things a bit!

First Steps

The configuration of our terminal is defined by the variable PS1. To change what your terminal displays, you just need to type in it

export PS1='I am so fancy šŸ˜„ $ '
Enter fullscreen mode Exit fullscreen mode

Magic! you now have a custom terminal. But oh misery, when you close and boot it up again, your terminal will be going back to boring old normal. Don't worry, I got you, there is a way of making things more durable.

The secret lies in the .bashrc file.

Go ahead and type the following command into your terminal

cd
vim .bashrc
Enter fullscreen mode Exit fullscreen mode

This will open a file looking like this
Alt Text

We know from before that the variable PS1 holds our prompt display. Go to the following line and uncomment

force_color_prompt=yes
Enter fullscreen mode Exit fullscreen mode

then go to the line below

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
Enter fullscreen mode Exit fullscreen mode

Huray! this is your traditional Ubuntu terminal prompt.

Ok, great, we have it.. now what?

Now comes the fun, it is time to customize things a bit. But first, let's understand this mess.

Here is a short description of the different parts

  • ${debian_chroot:+($debian_chroot)}: this part is explained here in a very good way, I encourage you to read it
  • \[\033[01;32m\]...\[\033[00m\]: Are the opening and closing tags of bash text styling
  • \u, \h and \w: respectively user, machine name and current path

In order not to get too much content in, we will first just create a simple prompt that will look like this

šŸ˜šŸ˜ DEV MADE ME DO THIS šŸ˜šŸ˜ $ 
Enter fullscreen mode Exit fullscreen mode

(with more colors)

Let's customize

In your .bashrc go to

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
Enter fullscreen mode Exit fullscreen mode

We will start by removing the unwanted boring content. We will remove the username and machine name but will let the path in. Always nice to know where you are. Your code should look like:

PS1='${debian_chroot:+($debian_chroot)}:\[\033[01;34m\]\w\[\033[00m\]\$ '
Enter fullscreen mode Exit fullscreen mode

to apply the changes, save your current modification and type in your terminal:

source .bashrc
Enter fullscreen mode Exit fullscreen mode

We have to continue the work, enter again in your .bashrc and change the code to the following:

PS1='${debian_chroot:+($debian_chroot)}šŸ˜šŸ˜ DEV MADE ME DO IT šŸ˜šŸ˜ \[\033[01;34m\]\w\[\033[00m\]\$ '
Enter fullscreen mode Exit fullscreen mode

Alt Text

This is not so bad... right? But we miss something... I know! Colors!

We need to try and make a rainbow. Basically how the styling work is as follows. As seen before, we have \[\033[01;32m\] as opening tag and \[\033[00m\] as closing tag.

Adding Colors in your Life

openning

\[\033[01;32m\] is the bash way of saying increased intensity with color green. In this string of characters, the 01 means increase intensity and the 32 means green. Try 02 instead of 01 and your text will be a bit transparent. Try 33 instead of 32 and your text will become brownish. DON'T FORGET TO SOURCE .BASHRC.

closing

\[\033[00m\] really just means no more styling. Yep, that's it.


So! let's finish our beautiful rainbow of colors. We will use the following colors:

red: 91
yellow: 93
green: 92
light blue: 96
blue: 94
purple: 95
Enter fullscreen mode Exit fullscreen mode

which will give us:

PS1='${debian_chroot:+($debian_chroot)}šŸ˜šŸ˜ \[\033[01;91m\]D\[\033[00m\]\[\033[01;93m\]E\[\033[00m\]\[\033[01;92m\]V\[\033[00m\] \[\033[01;96m\]M\[\033[00m\]\[\033[01;94m\]A\[\033[00m\]\[\033[01;95m\]D\[\033[00m\]\[\033[01;94m\]E\[\033[00m\] \[\033[01;96m\]M\[\033[00m\]\[\033[01;92m\]E\[\033[00m\] \[\033[01;93m\]D\[\033[00m\]\[\033[01;91m\]O\[\033[00m\] \[\033[01;93m\]I\[\033[00m\]\[\033[01;92m\]T\[\033[00m\] šŸ˜šŸ˜ \[\033[01;34m\]\w\[\033[00m\]\$ '
Enter fullscreen mode Exit fullscreen mode

Alt Text

Alright... This was of course just to showcase what you could do. I personally went for something more basic:

Alt Text

Congrats! You are now a master of personalizing your command prompt. In order to learn more about how to visually customize your prompt, use the link right below to find more resources. You will be able to create crazy blinking animated terminal sessions with it, trust me it's fun:

It would be nice to see what you guys built, so let us know in the comments!

Til next time.
Mike


About me

I am a partner at MMPG Consulting, a firm active in the custom software development industry in the Spanish and Swiss markets.

For more content, you can add me on LinkedIn or shoot me a DM if you want to discuss specific topics, your software or an idea you want to implement.

šŸ’– šŸ’Ŗ šŸ™… šŸš©
mikgross
Mikael

Posted on June 22, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related