Colored zsh prompt with git support
A simple way to create a simple colored prompt with git support which may look like this:
TL;DR
- If the folder
~/.zsh/
doesn’t exist yet, runmkdir ~/.zsh
to create it. - Run
git clone git@github.com:olivierverdier/zsh-git-prompt.git ~/.zsh/zsh-git-prompt
-
Add the following at the top of your
~/.zshrc
file# --- Configure zsh prompt --- source ~/.zsh/zsh-git-prompt/zshrc.sh PROMPT='%B%F{9}%n%F{reset}🐒 :%F{10}%C%F{reset}%b $(git_super_status) %# '
Instructions with a bit more context
Follow these instructions on a unix system (like OSX on a Mac) in a zsh shell 😉:
-
Get zsh-git-prompt
Clone the zsh-git-prompt repository into the folder
~/.zsh/zsh-git-prompt
(~
denotes the home directory). -
Add the following at the top of
~/.zshrc
:source ~/.zsh/zsh-git-prompt/zshrc.sh
-
Configure the colors
Right below the line
source ~/.zsh/zsh-git-prompt/zshrc.sh
in my.zshrc
file I addPROMPT='%B%F{9}%n%F{reset}🐒 :%F{10}%C%F{reset}%b $(git_super_status) %# '
Notes:
- I picked colors red (
F{9}
) and green (F{10}
) - I like emojis 😅. Do you want to keep the
🐒
? -
Run the following to view all 256 possible color values:
for i in {1..256}; do print -P "%F{$i}Color : $i"; done;
This should give you the following output (first few lines):
- To adapt the colors, change the numbers, e.g. change
%F{9}
to%F{5}
for a pink color. - Whatever is in-between
%F{your_color}
and%F{reset}
takes on the chosen coloryour_color
. %F{reset}
is important to reset the colors. Otherwise everything that followsf would keep the color set in%F{your_color}
- This StackOverFlow reply made me learn about this.
- I picked colors red (
Alternatives
- Oh My Zsh is the most popular alternative but all of the possible configurations and plugins overwhelmed me a bit. I like the simplicity of this approach.
Discuss on Twitter ● Improve this article: Edit on GitHub