This is a simple, lightweight, and nice looking prompt that runs quickly even in very slow shells like MSYS2, Cygwin and WSL.
It shows the short name of the current environment (distribution, OS, etc.,) the git branch when in a git checkout, the last command exit status (green checkmark for success and red X mark for non-zero exit) and an optional clean/dirty git status indicator.
This prompt is compatible with bash, zsh and some other POSIX sh implementations such as busybox, (d)ash, ksh, etc..
It's based on the Solarized Extravagant theme in bash-git-prompt.
I also made a PowerShell version of this prompt.
mkdir -p ~/source/repos
cd ~/source/repos
git clone https://github.com/rkitover/sh-prompt-simple
Somewhere in your shell startup file such as ~/.bashrc
put something like this:
SPS_STATUS=1
. ~/source/repos/sh-prompt-simple/prompt.sh
. For bash I also recommend:
shopt -s checkwinsize
PROMPT_COMMAND='history -a'
.
To show a clean/dirty git status indicator, set this variable:
SPS_STATUS=1
. This is disabled by default because it makes the prompt much slower on things like MSYS2/Cygwin, but it will work fine on Linux. You can also try it on MSYS2/Cygwin and see if the slowdown is acceptable for you.
You can turn it on or off without re-sourcing any files, so if it's particularly slow in a large repository you can just do:
unset SPS_STATUS
, to turn it off.
It may be particularly slow when entering a repository, but after that it will be cached and the prompt will be much faster.
The prompt tries to detect bash/busybox/(d)ash/ksh and use zero-width escape
sequences if found. If your shell does not support the \[ ... \]
zero-width
escape sequences, for example because you didn't turn on the fancy prompt
feature in busybox, you can turn them off by setting:
SPS_ESCAPE=0
, or force them on with:
SPS_ESCAPE=1
. If you have a wide enough window, the prompt will work more or less ok without the escape sequences in shells that don't support them.
By default the window title is set to the domain of the host or the hostname if
on a local network (only two full hostname parts, such as machine.localnet
.)
To turn this off set:
SPS_WINDOW_TITLE=0
. This is a work in progress and I plan to expand this feature to allow for complex window titles using formats and evaluated variables/commands.