Make your shell prompt great again
By Tomasz Kuczma
What is shell prompt? Why it is not great nowadays? How to make it so again? In this article, I will show you a tool I have been successfully using for a long time. Liquid prompt - bash & zsh prompt which makes it great again!
What is shell prompt?
Shell prompt is the text which is displayed in a terminal by a system shell to prompt a user for an input. In most Linux distributions, it looks like this:
user@hostname:~ $
It consists of the name of the logged-in user, hostname, current directory and command prompt ($
character or #
for superuser).
Usually, it is useless on personal computers as you know that you are logged in as you on your computer.
To execute commands which require root privileges, you most probably use sudo
(instead of login as root or switching user to root using su
) so even the command prompt is always the same.
The only relevant thing might be the working directory, so if somebody disturbs you, you don’t need to enter pwd
to realize where were you.
The truth is that the shell prompt can be more useful when you ssh
through different remote machines than just operating on the local machine.
It could be also more useful in the times of first Unixes due to other technical limitations (hard input and output interfaces - see why Unix commands are short
) and less society familiarity with computers.
How to make it useful again?
It is really simple. Just add useful information to the shell prompt :) You can do that by editing your .bashrc
file and exporting PS1
variable:
export PS1="MY PROMPT\$ "
Don’t forget to source ~/.bashrc
in the end :)
You can even use an online generator to create own prompt. It’s not my best option but you can check this out here
.
In the past, I spent a lot of time to design my own prompt suitable for my needs. But nowadays I can clearly say it wasn’t a good investment in my productivity. It was just standard prompt which just looked different even though it has two or free additional fields. So my advice is to do not invest time in design own prompt just using some ready to go solution. For a few years, I have used Liquid prompt which I found somehow googling on the internet.
Liquid prompt
Liquid prompt makes your prompt look like in the example above. It shows that my processor is bussy, battery is not charging, current user and hostname, current directory (with ability to hide redundant part), git repository information and status from last command and more! And it uses so many colors which make you look like a pro ;) I already did quite a good showcase above but you can also take a look into official GitHub repository to see what it gives you. There is a really easy configuration & installation guide. If you are using newer Ubuntu, the Liquid prompt is even added in standard repository so you can just use apt to install it and activate it.
sudo apt install liquidprompt \
&& liquidprompt_activate
Note that the Ubuntu package uses debian.theme
by default, not the original liquid.theme
but this suits me too.
One thing I have changed in the default config is to block displaying hostname on a local machine so I have more space for useful stuff.
Geeks might wanna enable an analog clock too 🕣 - just for fun ;)
What features I love about it
The most important thing is that the default setup is powerful.
- I see when system resources are in bad shape: battery level goes down, CPU utilization is high, etc.
- It integrates with git (and other SCMs). I always know on which git branch I am and if there are some local changes without typing any extra command.
To be honest it just integrates
git-prompt.sh
(see official git documentation ) but does it smoothly. - It is adaptive! It shows only important information (e.g. uses thresholds to show some information like CPU utilization or shortens current directory path) so you can focus on important things instead of blinking colorful characters on the black screen.
- It shows the last command status code (if different than 0). Small thing but extremely useful. It helps realize that your command was not done entirely and failed at some point.
- It displays execution time so you can finally understand how slow are your tools and realize how much time they steal from you.
- It supports bash & zsh. This allows you to use it in your favorite shell.
Is there an alternative?
There is also oh-my-zsh which looks like a good alternative. It targets zsh only but it should not be a problem to switch I think. It might be worth trying zsh as MacOS changes default shell to zsh starting from version Catalina 10.15 which looks like a big step. If you have concerns about licensing, it uses MIT license in contrast to GNU Affero GPL use by Liquid prompt.
Conclusion
Just make you prompt useful again :) but use ready to go solution and don’t waste your time doing your own prompt. Two presented tools do it already well but Liquid prompt is my choice.
Software engineer with a passion. Interested in computer networks and large-scale distributed computing. He loves to optimize and simplify software on various levels of abstraction starting from memory ordering through non-blocking algorithms up to system design and end-user experience. Geek. Linux user.