Linux users, software developers and power users alike spend a lot of time in the command-line prompt. The default Bash shell that ships in most Linux distributions have stayed pretty much unchanged for years and years. We wanted to explore how to improve the every day command-line experience, and eventually came very fond of the Liquid Prompt, which we recommend all Linux users to check out.
Why Liquid Prompt?
A lot of developers, in particular Mac users, seem to be using zsh nowadays, and extensions such as oh-my-zsh and powerline. While these look very fancy, the installing zsh with a lot of plugins quickly leads to a messy collection of scripts. At first it can feel cool, but one quickly runs into upgrade and interoperability issues. Also, changing the default shell from bash to zsh has profound effects on how shell scripts behave and the overall experience using SSH and working on multiple hosts can degrade.
To cut through the flashy blog posts and marketing fluff we turned to the Debian Developers mailing list asking for thoughtful advice from true command-line professionals. From this advice we learned about the Liquid Prompt, a Bash extension that has been around since 2012 and packaged in since 2016 in Debian (and its derivates, such as Ubuntu). Check out the threads in May, June and July if you want to learn about the other tips shared on the mailing list.
Main innovation: progressive disclosure
The default prompt in Liquid Prompt is very simple:
It shows the username (on this test machine it is ‘vagrant’) and hostname (on this machine it is ‘wordpress’) the path and the prompt sign $. This is basically the same as the default Bash prompt, but with colors, which will be explained later.
However, it will automatically expand to tell the user more information when there is something special going on, hence the name ‘liquid’:
In the screenshot above, there is now a lot of information available:
- the
3&
tells that there are 3 processes running the in background - the
2z
tells that there are 2 processes stopped - the path is expanded and after it the master tells the git branch name
- the
+2/-0
tells that there are local commits that have not been pushed to the remote - the
*
tells that there are also uncommitted changes - the
15s
is the unusually long duration of the previous command - the
147
is the non-zero exit code from the previous command and - the
±
as the prompt tells that the directory uses git for version control
The next screenshot shows another situation:
Here the prompt text and colors tells that:
- the user is now ‘mysql’
- the
@
-character is yellow, which means that there is no X11 forwarding available - the hostname ‘wordpress’ is bold and colored, which tells that the prompt is used over SSH
- the colon
:
is red as an indication that the current user does not have write permissions to the current path - the long path name has been shortened with
...
to save space for the prompt
This is a great design principle, because extra information is revealed only when it is relevant, and otherwise the prompt stays short and sweet. The fact that Liquid Prompt is an extension to Bash means that there are no custom shell language and all of your Bash scripts work just as they should. There is no right aligned extra stuff that is prone to rendering errors and the whole layout works well in any screen/resolution or screen/tmux use without getting messed up. Liquid Prompt is an interoperable, stable and clean piece of software we can warmly recommend as your new daily tool.
To learn about all features, check out Liquid Prompt’s README on Github.
Installation
Liquid Prompt is available by default in most Linux distributions. On Debian/Ubuntu you can simply run apt install liquidprompt
. For each user that wants to activate it run liquidprompt_activate
. This command adds to .bashrc
the following lines:
# Only load liquidprompt in interactive shells, not from a script or from scp
echo $- | grep -q i 2>/dev/null && . /usr/share/liquidprompt/liquidprompt
The new prompt will be active starting from the next new command-line session a user starts.
To also have the laptop battery status and temperature showing, one also needs to have the extra packages acpi
and lm-sensors
installed.
Customize settings
It is possible to fine tune how Liquid Prompt works by editing the settings file at ~/.config/liquidpromptrc
. While the default settings of Liquid Prompt are mostly fine, the following modifications made it feel a tad more usable:
# Show laptop batter level only if below 20%
LP_BATTERY_THRESHOLD=20
# Show CPU load only if above 40%
LP_LOAD_THRESHOLD=40
# Don't show hostname on localhost
LP_HOSTNAME_ALWAYS=0
# Don't show user is it is you
LP_USER_ALWAYS=0
# Always show the wall clock at the beginning of the line.
LP_ENABLE_TIME=1
# Show duration of previous command only is it was over 10s
LP_ENABLE_RUNTIME=10
# Never show laptop temperature
LP_ENABLE_TEMP=0
# Always enable colors if accessed via SSH
LP_ENABLE_SSH_COLORS=1
With the settings above the default prompt will look as:
Additionally you might want to make these additions to your .bashrc
file:
# Ensure Gnome Terminal shows the prompt correctly
PROMPT_COMMAND='echo -ne "\033]2;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
PROMPT_COMMAND="history -a; history -c; history -r;$PROMPT_COMMAND"
# This existing block should come after the lines above
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033>
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
Extra tip: make use of a bigger bash history, the Liquid Prompt compatible way
# Store run time in .bash_history history
HISTTIMEFORMAT="[%F %T] "
# Collect very long history, disk space is cheap
HISTSIZE=10000000
HISTFILESIZE=10000000
# Append each command to history, don't overwrite
shopt -s histappend
# Append each command to history immediately after it ran, dont' wait until the session ends
PROMPT_COMMAND="history -a; history -c; history -r;$PROMPT_COMMAND"
# Ignore duplicates and commands that started with a space character
HISTCONTROL=ignoredups:ignorespace
Want to find more hidden gems?
While doing research on this topic we came across a great Youtube video series by Jonathan Carter (highvoltage): Debian Package of the Day and in particular the Week of Terminal Emulators in episodes 46–51.
2 thoughts on “Pimp your bash with Liquid Prompt”