Polyglot Prompt
The Polyglot Prompt is a dynamic prompt for zsh
, bash
, ksh93
, mksh
, pdksh
, dash
, and busybox ash
that uses basic ASCII symbols (and color, when possible) to show:
- the username
- whether a session is local or remote over SSH
- an abbreviated path
- the Git branch and status
- the exit status of the last command, if it was not zero
- any virtual environment created with
virtualenv
,venv
,pipenv
,poetry
, orconda
Note: There is also support for color in pdksh
.
Table of Contents
- Basics
- Local and Remote Sessions
- Abbreviated Paths
- Git Branch and Status
- Exit Status
- Virtual Environments
- Kubernetes Integration
- Enabling
vi
editing mode inzsh
andbash
Basics
The central functions of the prompt are the same in all supported shells:
Additionally, in zsh
and in bash
v4.3 and higher, the Polyglot Prompt indicates vi
insert mode with a +
, and command mode with a :
, at the beginning of the prompt:
See below for instructions on how to enable vi
mode in your shell.
Local and Remote Sessions
When a session is local, only the username is shown; when it is remote over SSH (or mosh
), the hostname is also shown:
Note: It is exceedingly difficult to determine with accuracy whether a superuser is connected over SSH or not. In the interests of providing useful and not misleading information, this prompt always displays both username and hostname for a superuser in reverse video.
Abbreviated Paths
In all shells, by default the Polyglot Prompt emulates the behavior that bash
uses when PROMPT_DIRTRIM
is set to 2
: a tilde (~
) is prepended if the working directory is under the user's home directory, and then if more than two directory elements need to be shown, only the last two are displayed, along with an ellipsis, so that
/home/pi/src/neovim/config
is displayed as
whereas
/usr/src/sense-hat/examples
is displayed as
that is, without a tilde.
If you would like to display a different number of directory elements in your Polyglot Prompt, set the environment variable $POLYGLOT_PROMPT_DIRTRIM
in an rc file thus:
POLYGLOT_PROMPT_DIRTRIM=4 # Or whatever number you like
Setting POLYGLOT_PROMPT_DIRTRIM=0
disables path abbreviation, although $HOME
will still be displayed as ~
.
Git Branch and Status
If the current directory contains a Git repository, the Polyglot Prompt displays the name of the working branch, along with some symbols to show changes to its status:
Git Status | Symbol |
---|---|
Diverged | &* |
Behind | & |
Ahead | * |
New file(s) | + |
Deleted | x |
Modified | ! |
Renamed | > |
Untracked | ? |
POLYGLOT_SHOW_UNTRACKED
If you are working on an extremely large Git repository, such as an operating system kernel, calculating the Git status can be very slow. If you need to, you may set POLYGLOT_SHOW_UNTRACKED=0
, which will cause the Polyglot Prompt to ignore the Git status for untracked files. This will have the effect of speeding up the display of the prompt considerably.
Exit Status
If the exit status of the most recently executed command is other than zero (zero indicating success), the exit status will be displayed to the left of the prompt:
Virtual Environments
The Polyglot Prompt will display any active virtual environment created with virtualenv
, venv
, pipenv
, poetry
, or conda
at the beginning of the prompt:
Kubernetes Integration
If you are using the Polyglot Prompt with bash
or zsh
, you may add the Kubernetes context and namespace to your prompt with the add-on package polyglot-kube-ps1.
Enabling vi
editing mode in zsh
and bash
The Polyglot Prompt does not enable vi
editing mode for you. In zsh
, you may add
bindkey -v
to your .zshrc
; for bash
, either put
set-editing-mode vi
in your .inputrc
or
set -o vi
in your .bashrc
.