2012-07-19 08:17:32 -04:00
|
|
|
Liquid prompt -- A useful adaptive Bash prompt
|
|
|
|
==============================================
|
|
|
|
|
|
|
|
Liquid prompt is a smart prompt for the "Bourne-Again" Unix shell (bash).
|
|
|
|
|
|
|
|
The basic idea of the liquid prompt is to nicely display useful informations on
|
|
|
|
the shell prompt, only when they are needed. It adds carefuly chosen colors to
|
|
|
|
draw your attention on what differs from the normal context. Thus, you will
|
|
|
|
notice what changes, when it changes, because you do not become accommodated to
|
|
|
|
informations that are always displayed in the same way.
|
|
|
|
|
|
|
|
|
|
|
|
## FEATURES
|
|
|
|
|
|
|
|
If there is nothing special in the current context, the liquid prompt is close
|
|
|
|
to a default prompt:
|
|
|
|
|
|
|
|
`[user:~] $ `
|
|
|
|
|
|
|
|
If you have ran one command in background that is still running and that you are
|
2012-08-04 13:55:56 -04:00
|
|
|
in a git repository on a server, at branch "myb":
|
2012-07-19 08:17:32 -04:00
|
|
|
|
|
|
|
`1r [user@server:~/liquidprompt] myb ± `
|
|
|
|
|
|
|
|
A liquid prompt displaying everything may look like this:
|
|
|
|
|
2012-08-10 08:40:50 -04:00
|
|
|
`⌁24% ⌂42% 3d/2&/1z [user@server:~/ … /code/liquidprompt]↥ master(+10/-5,3) 125 ± `
|
2012-07-19 08:17:32 -04:00
|
|
|
|
|
|
|
It displays:
|
|
|
|
|
|
|
|
* the average of the batteries remaining power, if it is under a given
|
2012-07-19 08:48:20 -04:00
|
|
|
threshold, with a colormap too;
|
2012-07-19 08:17:32 -04:00
|
|
|
* the average of the processors load, if it is over a given limit, with a
|
2012-07-19 08:48:20 -04:00
|
|
|
colormap that became more and more noticeable with increasing load;
|
2012-08-10 08:28:18 -04:00
|
|
|
* the number of detached sessions (`screen`), if there is any;
|
2012-07-19 08:48:20 -04:00
|
|
|
* the number of attached sleeping jobs (when you interrupt a command with Ctrl-Z
|
|
|
|
and bring it back with `fg`), if there is any;
|
2012-07-19 08:17:32 -04:00
|
|
|
* the number of attached running jobs (commands started with a `&`), if there is
|
|
|
|
any;
|
2012-07-19 09:08:18 -04:00
|
|
|
* the current user, in bold yellow if it is root, in light white if it is not
|
|
|
|
the same as the login user;
|
2012-07-19 08:17:32 -04:00
|
|
|
* the current host, if you are connected via an SSH or telnet connection, with
|
|
|
|
different colors for each case;
|
2012-07-29 16:20:12 -04:00
|
|
|
* a green colon if the user has write permissions on the current directory,
|
|
|
|
a red one if he has not;
|
2012-07-29 16:09:11 -04:00
|
|
|
* the current directory in bold, shortened if it takes too much space, while
|
|
|
|
preserving the first two directories;
|
2012-08-09 06:11:51 -04:00
|
|
|
* an up arrow if an HTTP proxy is in use;
|
2012-07-19 08:17:32 -04:00
|
|
|
* the name of the current branch if you are in a version control repository
|
|
|
|
(git, mercurial or subversion), in green if everything is up to date, in red if
|
|
|
|
there is changes, in yellow if there is pending commits to push;
|
2012-08-04 13:52:24 -04:00
|
|
|
* the number of added/deleted lines, if changes have been made and the number
|
|
|
|
of pending commits, if any;
|
2012-07-19 08:17:32 -04:00
|
|
|
* the error code of the last command, if it has failed in some way;
|
2012-08-10 08:40:50 -04:00
|
|
|
* a smart mark: ± for git directories, ☿ for mercurial, ‡ for svn, $ for simple
|
|
|
|
user, a red # for root.
|
2012-07-19 08:17:32 -04:00
|
|
|
|
2012-08-04 13:05:34 -04:00
|
|
|
You can temporarily deactivate the liquid prompt and come back to your previous
|
|
|
|
one by typing `prompt_off`. Use `prompt_on` to bring it back.
|
|
|
|
|
2012-07-19 08:17:32 -04:00
|
|
|
|
2012-08-01 13:33:32 -04:00
|
|
|
## INSTALL
|
2012-07-19 08:17:32 -04:00
|
|
|
|
|
|
|
Include the file in your bash configuration, for example in your `.bashrc`:
|
|
|
|
|
2012-07-19 08:48:20 -04:00
|
|
|
`source liquidprompt.bash`
|
2012-07-19 08:17:32 -04:00
|
|
|
|
2012-08-01 13:33:32 -04:00
|
|
|
Copy the `liquidpromptrc-dist` file in your home directory as
|
2012-08-04 11:47:56 -04:00
|
|
|
`~/.config/liquidpromptrc` or `~/.liquidpromptrc` and edit it according to your
|
|
|
|
preferences. If you skip this step, the default behaviour will be used.
|
2012-08-01 13:33:32 -04:00
|
|
|
|
2012-07-19 08:17:32 -04:00
|
|
|
|
2012-08-10 08:30:13 -04:00
|
|
|
## DEPENDENCIES
|
|
|
|
|
|
|
|
Apart from obvious ones, some features depends on specific commands
|
|
|
|
(if you want a git support you'd better install git…):
|
|
|
|
|
|
|
|
* battery status need `acpi`,
|
|
|
|
* detached sessions is looking for `screen`.
|
|
|
|
|
|
|
|
For other features, the script uses commands that should be available on a large
|
|
|
|
variety of unixes: `tput`, `grep`, `awk`, `sed`, `ps`, `who`.
|
|
|
|
|
|
|
|
|
2012-07-19 08:17:32 -04:00
|
|
|
## PUT THE PROMPT IN A DIFFERENT ORDER
|
|
|
|
|
2012-08-01 13:33:32 -04:00
|
|
|
You can configure some variables in the `~/.liquidpromptrc` file:
|
|
|
|
|
|
|
|
* `LP_BATTERY_THRESHOLD`, the maximal value under which the battery level is
|
|
|
|
displayed
|
|
|
|
* `LP_LOAD_THRESHOLD`, the minimal value after which the load average is
|
|
|
|
displayed
|
|
|
|
* `LP_PATH_LENGTH`, the maximum percentage of the screen width used to display
|
|
|
|
the path
|
|
|
|
* `LP_PATH_KEEP`, how many directories to keep at the beginning of a shortened
|
|
|
|
path
|
2012-08-07 14:52:32 -04:00
|
|
|
* `LP_REVERSE`, choose between reverse colors (black on white) or normal theme
|
|
|
|
(white on black)
|
|
|
|
* `LP_HOSTNAME_ALWAYS`, choose between always displaying the hostname or showing
|
|
|
|
it only when connected with a remote shell
|
2012-08-01 13:33:32 -04:00
|
|
|
|
2012-07-19 08:17:32 -04:00
|
|
|
Most of the display is prepared in the `__set_bash_prompt` function, apart from
|
|
|
|
features that needs several colors (such as the load colormap). You can sort
|
2012-08-10 08:28:18 -04:00
|
|
|
what you want to see by editing the `PS1` variable here.
|
2012-07-19 08:17:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
## KNOWN LIMITATIONS AND BUGS
|
|
|
|
|
2012-08-10 08:28:18 -04:00
|
|
|
* detached sessions only looks for `screen`, a `tmux` support would be nice…
|
2012-07-19 08:17:32 -04:00
|
|
|
* Does not display the number of commits to be pushed in Mercurial repositories.
|
|
|
|
* Subversion repository cannot display commits to be pushed, this is a
|
|
|
|
limitation of the Subversion versionning model.
|
2012-08-09 06:11:51 -04:00
|
|
|
* The proxy detection only uses the `$http_proxy` environment variable.
|
2012-07-19 08:17:32 -04:00
|
|
|
|