
A fast zsh prompt that packs in a lot of Git status info
Last Updated

Running Git commands between prompts to add status information in your command line prompt can significantly increase the time it takes your zsh prompt to render. And if you aren’t already familiar with zsh prompt code idioms and less-common Git commands, it can take a lot of research, and trial and error.
With Git Prompt Kit, a collection of Git status info zsh prompt components, your prompt can stay snappy, and your prompt-customizing the code you write is clear and terse.
Try it out!
The clear and concise nature of Git Prompt Kit-powered zsh themes is easy to show in an article, but the components’ dynamic content and customizability are not. For that, install Git Prompt Kit… or try out the interactive web demo!
Another project to check out
Hometown is my zsh theme built on Git Prompt Components. It’s a good option if you want a plug-and-play carefully designed Git-focused prompt. Read about it in Hometown: A Dynamic, Highly Configurable Git-Focused Zsh Theme.
Say you want your prompt to show
% when you aren’t root and # when you are, colored according to whether or not the previous command errored.One vanilla implementation is
set_prompt_vars() {
psvar=( )
git_branch=$(git branch --show-current 2>/dev/null)
if [[ -n $git_branch ]]; then
psvar+=( $git_branch )
else
psvar+=( $(git rev-parse --short 2>/dev/null) )
fi
if [[ $(git status --porcelain 2>/dev/null) ]]; then
psvar+=( magenta )
fi
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd set_prompt_vars
# directory
PROMPT='%F{blue}%2~%f '
# Git HEAD
PROMPT+="%(2V.%F{%2v}.)%1v%f%(1V. .)"
# prompt char
PROMPT+='%F{%(?.green.red)}%#%f 'Coming up with that requires knowledge of zsh function autoloading, hooks, arrays, conditionals, output redirection and coloring, psvar, and prompt expansion; and knowledge of Git commands for checked-out branch’s name, the checked-out commit’s SHA, and whether the working tree is dirty.[1]
On my machine, this vanilla-code prompt takes about 80ms to render[2] which slow enough that you’re likely to perceive lag[3].
With Git Prompt Kit components, the entire thing becomes
# load Git Prompt Kit and then
PROMPT='$GIT_PROMPT_KIT_CWD '
PROMPT+='${GIT_PROMPT_KIT_HEAD:+$GIT_PROMPT_KIT_HEAD }'
PROMPT+='$GIT_PROMPT_KIT_CHAR 'On my machine, the Git Prompt Kit-based prompt takes under 15ms to render[4], which is fast enough that you’re very unlikely to perceive a delay.
It has the same features plus enhancements:
And that’s the power of just three of Git Prompt Kit’s nearly thirty components!
Learn more in the Git Prompt Kit docs.
If you like it, or just feel like saying “nice work”, let me know by starring the GitHub repo.
Docs links for the curious:
psvar)git-branch --show-current2>/dev/null)if…then…else)[[ -n … ]])arr+=( el ))git-rev-parse --shortgit-status --porcelainadd-zsh-hook)precmd)%v, %(…))%F, %f)%~, %#)As measured by zsh-prompt-benchmark ↩︎
See https://github.com/romkatv/zsh-bench#how-fast-is-fast ↩︎
Git Prompt Kit uses gitstatus, an accelerated alternative to Git’s own status commands. ↩︎

Hometown: A Dynamic, Highly Configurable Git-Focused Zsh Theme
A fast zsh prompt that packs in a lot of Git status info

The command line (mostly Git) abbreviations I rely on
The abbreviations that have saved me countless terminal keystrokes, and the commands to add them to your zsh or fish setup

My .zshrc Zsh Configuration, Annotated
How I set up my interactive shell

Writing zsh tab completions can be straightforward
How I add tab completion for the zsh command line