A zsh prompt that displays information about the current git repository.
In particular the branch name, difference with remote branch, number of files staged, changed, etc.
(an original idea from this blog entry).
The prompt may look like the following:
(master↑3‣1): on branchmaster, ahead of remote by 3 commits, 1 file changed but not staged(status♦2): on branchstatus, 2 files staged(master‣7…): on branchmaster, 7 files changed, some files untracked(experimental↓2↑3): on branchexperimental; your branch has diverged by 3 commits, remote by 2 commits(:70c2952): not on any branch; parent commit has sha170c2952
Here is how it could look like when you are ahead by 2 commits, and have 3 staged files, 1 changed but unstaged file, and some untracked files, on branch dev:
The symbols are as follows:
- Status Symbols
⚡: repository clean ♦n: there are nstaged files≠n: there are nunmerged files‣n: there are nchanged but unstaged files…: there are some untracked files
- Branch Symbols
↑n: ahead of remote by ncommits↓n: behind remote by ncommits↓m↑n: branches diverged, other by mcommits, yours byncommits:: when the branch name starts with a colon :, it means it's actually a sha1, not a branch (although it should be pretty clear, unless you name your branches like sha1 :-)
Create the directory
~/.zsh/git-promptif it does not exist (this location is customizable).Move the file
gitstatus.pyinto~/.zsh/git-prompt/.Source the file
zshrc.shfrom your~/.zshrcconfig file, and, optionally, configure your prompt. So, somewhere in~/.zshrc, you should have:source path/to/zshrc.sh # configure the following, or leave it commented out: # PROMPT='%B%m%~%b$(prompt_git_info) %# '
You may also redefine the function
prompt_git_info(after thesourcestatement) to adapt it to your needs (change the colour, or the order of each piece of information). Take a look in the filezshrc.shto see what this function may look like.Go in a git repository and test it!
Enjoy!
