An intelligent prompt for zsh or bash with status line (window title) support
(C) Martin Väth (martin at mvath.de). This project is under the BSD license.
This is a collection of scripts which allow you to use an intelligent prompt for zsh or bash which also sets a corresponding hardstatus line (if your terminal supports it).
For a demo printing a simple default prompt, execute this in your shell:
printf '\e[0;33mme\e[36m@\e[32mhost\e[36m(my text)\e[1;32m~/very/l' \ && printf '\e[0;34m...\e[1;32mong/pathname\e[1;33m%%\e[0m\n'
Under X, tmux, or screen, the text will appear (slightly changed) in addition as your window title (status line).
The above line only displays the simplest prompt: You can see more information in the prompt if e.g. you are logged in by ssh, if you are in a directory with a git project, or if your last command exited unsuccessfully. A configuration file is supported in which you can easily customize the prompt (e.g. change colors or conditions), using standard shell code.
To install these scripts, copy them somewhere into your
the default configuration set_prompt.config can alternatively
also be copied into
To get support for zsh completion, put the files of the subdirectory
into your zsh's
For Gentoo, there is an ebuild in the mv overlay (available over layman).
The main program is
To get help for this program, call
set_prompt program outputs a valid string for
PS1 for zsh
(or for bash if the
-b option is used).
If used with zsh, the prompt usually expects that the
option is actived (
set_prompt program can be either executed or sourced by zsh,
bash, or any other POSIX compatible shell.
If you source it, you should source it in a subshell, of course
(which happens automatically with
The advantage of sourcing is that it is faster.
Note that even if sourced from bash, the
-b option is not implied.
By default, the set_prompt program sources the configuration file
(which is searched in
/etc/, and in your
So you should customize that file for your taste (e.g. to define the colors).
There is a sample script
for bash and zsh.
You can either execute it and
eval the output, like e.g.
if SOME_VARIABLE=`set_prompt.sh 2>/dev/null` then eval "$SOME_VARIABLE" else echo "set_prompt.sh not found" >&2 fi
or you can source it with
The latter has the disadvantage that it will die with an error if
set_prompt.sh cannot be found.
The above eval/sourcing of
set_prompt.sh defines a function
which acts like the set_prompt program with the difference that is sends the
output directly to
$PS1 and that appropriate options are used by default.
(In particular, default options are set for broken bash versions.)
set_prompt.sh script makes use of particular variables, so you might
want to look at the source and modify it for your needs before using it.
Finally, the prompt supports also the variable
$vcs_info_msg_0_ for zsh
(or optionally also for bash, although bash does not support it
This variable is set by
man zshcontrib for help on the latter).
There is an example script
which can be either treated with
eval or sourced, similarly as
This script will then activate the mechanism for
The configuration from
git_update instead of
git_update is in your
For security reasons, it is recommended to copy
git_update into your
because the latter will attempt to change (drop) permissions to those of
GIT_UPDATE_USER (defaults to
git_update fails to change the permissions,
git is not invoked for
security reasons. To drop this security measurement of
can export an empty
Since most users without privileges will want to support such an empty
git_prompt.zsh will do this for you if it is not possible
to drop permissions to the user
git_update is a separate command so that you can adapt it to your needs and
you can also use it other programs.
For example, if you are an emacs user, you might want to put
(setq vc-git-program "git_update")
~/.emacs to get the same security mechanism also for emacs.