09
Dec 2017
How to install zsh-git-prompt
Tags |
On Computer Technology
This post shows you how to install zsh-git-prompt, a program which customizes the zsh prompt by displaying additional information whenever a user cds into a git repository.
It is meant for readers of my other blog post, Haskell deep dive: zsh-git-prompt, who do not have zsh installed and/or do not have zsh-git-prompt installed.
NOTE: If you do not wish to install zsh and/or zsh-git-prompt but just want to check out what it does, head over to https://github.com/yanhan/zsh-git-prompt-docker for a Docker image that has zsh-git-prompt installed, along with instructions on how to use it.
Follow the instructions at https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH. For simplicity, you should use your system’s package manager to do it.
You are highly recommended to install oh-my-zsh, because it comes with some nice default settings and has a pretty big ecosystem of plugins and themes that you can later on choose to use for your customized setup.
Follow the installation instructions at https://github.com/robbyrussell/oh-my-zsh#basic-installation. I use the following command:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
This command might error out and say you are missing some programs. Install what it says that you lack using your package manager. When I was building the Docker image for this, it was complaining about missing make
and xz
.
We will be cloning the zsh-git-prompt git repo at your home directory.
cd ~
git clone https://github.com/olivierverdier/zsh-git-prompt.git
cd zsh-git-prompt
stack setup
stack build
stack install
The stack install
command should install a binary named gitstatus
in the ~/zsh-git-prompt/src/.bin/
directory (not to be confused with the actual git status
command). Do verify that this is the case.
Append the following to your ~/.zshrc
:
source ~/zsh-git-prompt/zshrc.sh
GIT_PROMPT_EXECUTABLE='haskell'
# an example prompt
PROMPT='%B%m%~%b$(git_super_status) %# '
Feel free to change the value of the PROMPT
, so long it includes the $(git_super_status)
somewhere. Personally, I use:
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_super_status)'
For more information on what those funny %B
, %m
, %{$fg[cyan]%}
, %c
and so on mean, please consult http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html
If you are already on zsh, just run the following to source the ~/.zshrc
and load the changes:
source ~/.zshrc
Otherwise, run zsh
to open a new zsh shell.
To see what zsh-git-prompt does, cd to a git repository. You should see that your prompt has additional information about the git repository, similar to (master|✔)
or (somebranch|…)
or (feature-branch|5↑2↓)
. If you cd to a directory which is not inside a git repo, you should not see that information.
Disclaimer: Opinions expressed on this blog are solely my own and do not express the views or opinions of my employer(s), past or present.