Liquid Prompt

From LinuxReviews
Jump to navigationJump to search
Liquid Prompt
Liquid Prompt changes the prompt when you are in a git tree
Liquid Prompt changes the prompt when you are in a git tree
Developer(s)Mark Vander Stel (Rycieos)
Initial release1.0 August 10, 2012; 9 years ago (2012-08-10)
Repositorygithub.com /nojhan/liquidprompt
Bugtrackergithub.com /nojhan/liquidprompt/issues
Written inBash/Zsh script
Operating systemLinux/Unix-like (anything using Zsh or Bash)
TypeCommand line prompt
Desktop rice
LicenseGNU Affero General Public License v3
Konsole.svg

Liquid Prompt is a adaptive and configurable command-line shell prompt extension. It provides a nice prompt with colors that displays a variety of information depending on what you are doing and how your box is doing. The default prompt is a short and simple one similar to the default bash prompt, but with colors. Liquid Prompt is a great alternative to manually setting the shell prompt using $PS1= that can enrich the everyday command-line experience.

Compatibility[edit]

Liquid Prompt can be used with bash, the most command-line shell interpreter on most GNU/Linux systems, and zsh, a widely used shell favored by iToddlers "developing" software neither they or anyone else actually use (like GNOME) on macOS. There are some exceptions, Deepin (uses dash) and a few other GNU/Linux distributions do not use bash. Most do.

You can check what shell your system defaults to with ls -al /bin/sh. It will most likely be a symbolic link to /bin/sh -> bash. Liquid Prompt will only work correctly if you use bash or zsh.

Installation[edit]

The Liquid Prompt git repository README.md has these installation instructions for acquiring the technology:

cd ~/.local
git clone https://github.com/nojhan/liquidprompt.git
cp liquidprompt/liquidpromptrc-dist ~/.config/liquidpromptrc

That places the liquidprompt folder in your $HOME/.local folder. The GitHub page instructs you to clone into $HOME/ which is something you can do if you want a really messy $HOME/ for some incomprehensible reason. Adjust paths in the following examples accordingly if you do that.

You may want to take a long look at ~/.config/liquidpromptrc in a text editor and change some values.

You can try Liquid Prompt out with:

source ~/.local/liquidprompt/liquidprompt

Use the patch below if you get an error message, there is a fair change that you will.

You can activate Liquid Prompt permanently by adding a line that loads it to either .bashrc or/and .zshrc:

# Only load Liquid Prompt in interactive shells, not from a script or from scp
[[ $- = *i* ]] && source ~/.local/liquidprompt/liquidprompt

Liquid Prompt is buggy right out the box on many systems as of the current git September 2020. A fix has been available in the Liquid Prompt issue tracker since April 1st, 2020[1]

diff --git a/liquidprompt b/liquidprompt
index 190ab8f..1860105 100755
--- a/liquidprompt
+++ b/liquidprompt
@@ -1514,7 +1514,7 @@ if (( LP_ENABLE_TEMP )); then
         # Return the hottest system temperature we get through the sensors command
         # Only the integer part is retained
         local -i i
-        for i in $(sensors -u |
+        for i in $(sensors -u 2> /dev/null|
                 sed -n 's/^  temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'); do
             (( $i > ${temperature:-0} )) && temperature=i
         done

Liquid Prompt may say something silly like:

ERROR: Can't get value of subfeature in1_input: Can't read

on each and every prompt without the above patch - depending on what hardware sensors are available. Don't forget to re-reload Liquid Prompt with:

source ~/.local/liquidprompt/liquidprompt

after applying the above patch. This bug will never be fixed. The Liquid Prompt developer has setup a special FAQ about it where he explains that installing a shell prompt script & getting an error message on each and every single prompt is somehow such "useful".

Features And Usability[edit]

Liquidprompt git 2020-09-27 mpv git.jpg
Liquid Prompt in action.

The Liquid Prompt adopts to what you are doing and what the box you are logged into is doing. It will show the battery status on laptops if the battery capacity is lower than a set LP_BATTERY_THRESHOLD (default to 75). It shows the load average if it is above a LP_LOAD_THRESHOLD (defaults to 60). CPU temperature is shown if it higher than LP_TEMP_THRESHOLD. Liquid Prompt will show what path you are in, but it will shorten it if it is longer than a LP_PATH_LENGTH threshold.

The way Liquid Prompt changes on you may be odd if you are used to a fixed shell prompt, and you probably are. However, the way it adopts and changes can be very useful. It will make you aware that you should probably connect a laptop to a charger if the battery is at 10% and you want to start a long compile.

Liquid Prompt can be specially useful on remotely managed servers where it could be useful to immediately see a high load average or a high CPU temperature when you login remotely.

Liquidprompt git 2020-09-27 git folder.jpg
Liquid Prompt showing that the system load is 100%. Notice how it changes when you enter a git folder.

Liquid Prompt has special features for certain software like git, svn, mercurial, fossil and bazaar. That's quite useful for developers who may enjoy seeing what git branch they are on and other useful when they are working code in a git repository. Liquid Prompt shows how many commits ahead and/or behind you are and show if there are uncommitted changes (indicated with *).

Liquid Prompt adds a small X& (where X is the number of processes) indicating actively running background-processes if you start background-processes with command &. It will also show you any stopped processes.

Liquid Prompt supports themes in case you don't like the default one. And it is highly configurable, if you don't want it to show something like the battery status then that's fine, you can turn that off in the configuration file. It can easily be configured to suit your particular needs and preferences.

Verdict And Conclusion[edit]

Liquid Prompt is overall a quite nice addition that makes the bash or zsh prompt nicer and more useful. It may be preferable to setting a custom colored bash prompt like..

File: $HOME/.bashrc
PS1='\[\e[0;38m\][\[\e[1;33m\]\u\[\e[0;32m\]@\[\e[1;35m\]\h \[\e[1;36m\]\W\[\e[0;38m\]]\$ \[\e[0;97m\]'

..since Liquid Prompt will provide a lot of useful information, depending on what you and your box is doing. The example above will just get you a fixed colored prompt.

The adaptive design is something that makes Liquid Prompt very attractive. It shows you what you need to know when you need to know it without getting in your way with information that's not relevant to the current situation. It may be useful to know your laptops battery status if it is at 20%, knowing that it is 100% when it plugged into a charger is less useful. The same goes for CPU load, CPU temperature and a lot of other things Liquid Prompt will show when it is needed. It really is a very nice little shell extension.

However, there are some valid questions one might want to raise about this software since it is something that will be running in all your terminal sessions. Why it is, by default, outright broken out of the box on two thirds of all the machines out there is one. The answer appears to be:

"We can't suppress errors that users need to know about, and while this one can be safely ignored sometimes, for some errors that is not the case."

This attitude makes Liquid Prompt annoying buggy software out of the box, and it may cause further annoyances down the line if/when you update the git tree. People don't randomly run sensors -u and it doesn't matter if it outputs an error if someone does; nothing bad happens. Nobody needs to, or wants to, see a useless message along with their shell prompt every single time it is shown.

A configuration option like LP_SHOW_ERRORS defaulting to 0 would solve this one.

The way the developer refuses to fix what is clearly a bug in Liquid Prompt is a red flag. As Linus Torvalds famously said: WE DO NOT BREAK USERSPACE. Bash and zsh work fine without Liquid Prompt, there is no error before the prompt is shown. Both break the moment you install Liquid Prompt (if you don't patch it) so it's fair and accurate to say that Liquid Prompt causing an error to appear before the shell prompt is a Liquid Prompt problem. If you're willing to patch it and you are prepared to waste time narrowing down problems and patching it if/when future issues then it may be for you, it is a overall fine little script that lets you get a mostly useful and informative shell prompt.

Footnotes[edit]

Links[edit]

The source repository & homepage is at github.com/nojhan/liquidprompt/.


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.