Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: digal/zsh-git-prompt
base: master
...
head fork: qqshfox/zsh-git-prompt
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 12 commits
  • 3 files changed
  • 0 commit comments
  • 4 contributors
Commits on Apr 01, 2012
@olivierverdier olivierverdier possible to disable caching (#8)
by defining the variable ZSH_THEME_GIT_PROMPT_NOCACHE, the caching is disabled, so the prompt is updated at every refresh
fa7ad8a
Commits on Apr 03, 2012
@olivierverdier olivierverdier Python3 compatibility (#4,#6) dcb8186
@olivierverdier olivierverdier minor fixes to README 12fce7c
@olivierverdier olivierverdier fix the examples in README 63ae834
@olivierverdier olivierverdier Readme: explanation of prompt structure 87358ac
Commits on Apr 25, 2012
@olivierverdier olivierverdier fix git commands working inside .git folder (#5)
some git commands still work inside a .git folder, so the prompt thinks we are in a regular git repo
c51d3f6
Commits on Jun 05, 2012
@rnc rnc Only set prompt dir if it has not already been set. Useful for overri…
…ding from shell init files.
50615c9
Commits on Jun 13, 2012
@zackrw zackrw Add precmd_update_git_vars to update the Git section before prompt re…
…nders
201cc16
Commits on Jun 14, 2012
@olivierverdier olivierverdier more pythonic way to find 'fatal' in string
use 'in' instead of find.
aca1522
@olivierverdier olivierverdier Merge remote-tracking branch 'xaq2892/master' 1f4ffcf
@olivierverdier olivierverdier Revert "Only set prompt dir if it has not already been set. Useful fo…
…r overriding from shell init files."

This reverts commit 50615c9.
350be32
Commits on Apr 16, 2013
@qqshfox qqshfox python3 compatibility 6fe111c
Showing with 35 additions and 21 deletions.
  1. +20 −14 README.rst
  2. +13 −6 gitstatus.py
  3. +2 −1  zshrc.sh
View
34 README.rst
@@ -4,19 +4,19 @@ Informative git prompt for zsh
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`_).
+(an original idea from this `blog post`_).
Examples
--------
The prompt may look like the following:
-* ``(master↑31)``: on branch ``master``, ahead of remote by 3 commits, 1 file changed but not staged
-* ``(status●2)``: on branch ``status``, 2 files staged
-* ``(master✚7…)``: on branch ``master``, 7 files changed, some files untracked
-* ``(master✖2✚3)``: on branch ``master``, 2 conflicts, 3 files changed
-* ``(experimental↓2↑3)``: on branch ``experimental``; your branch has diverged by 3 commits, remote by 2 commits
-* ``(:70c2952)``: not on any branch; parent commit has sha1 ``70c2952``
+* ``(master↑3|✚1)``: on branch ``master``, ahead of remote by 3 commits, 1 file changed but not staged
+* ``(status|●2)``: on branch ``status``, 2 files staged
+* ``(master|✚7…)``: on branch ``master``, 7 files changed, some files untracked
+* ``(master|✖2✚3)``: on branch ``master``, 2 conflicts, 3 files changed
+* ``(experimental↓2↑3|✔)``: on branch ``experimental``; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean
+* ``(:70c2952|✔)``: not on any branch; parent commit has hash ``70c2952``; the repository is otherwise clean
Here is how it could look like when you are ahead by 4 commits, behind by 5 commits, and have 1 staged files, 1 changed but unstaged file, and some untracked files, on branch ``dev``:
@@ -24,25 +24,31 @@ Here is how it could look like when you are ahead by 4 commits, behind by 5 comm
:alt: Example
-.. _blog entry: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/
+.. _blog post: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/
-Symbols
--------
+Prompt Structure
+----------------
+
+By default, the general appearance of the prompt is::
+
+ (<branch><branch tracking>|<local status>)
The symbols are as follows:
-* Status Symbols
+* Local Status Symbols
:✔: repository clean
:●n: there are ``n`` staged files
:✖n: there are ``n`` unmerged files
:✚n: there are ``n`` changed but *unstaged* files
:…: there are some untracked files
-* Branch Symbols
+* Branch Tracking Symbols
:↑n: ahead of remote by ``n`` commits
:↓n: behind remote by ``n`` commits
:↓m↑n: branches diverged, other by ``m`` commits, yours by ``n`` commits
- :\:: when the branch name starts with a colon ``:``, it means it's actually a hash, not a branch (although it should be pretty clear, unless you name your branches like hashes :-)
+
+* Branch Symbol
+ When the branch name starts with a colon ``:``, it means it's actually a hash, not a branch (although it should be pretty clear, unless you name your branches like hashes :-)
Install
-------
@@ -55,7 +61,7 @@ Install
# an example prompt
PROMPT='%B%m%~%b$(git_super_status) %# '
-#. You may also redefine the function ``git_super_status`` (after the ``source`` statement) to adapt it to your needs (to change the order in which the information is displayed). You may also change a number of variables (which name start with ``ZSH_THEME_GIT_PROMPT_``) to change the appearance of the prompt. Take a look in the file ``zshrc.sh`` to see how this function is defined, and what variables are available.
+#. You may also redefine the function ``git_super_status`` (after the ``source`` statement) to adapt it to your needs (to change the order in which the information is displayed). Define the variable ``ZSH_THEME_GIT_PROMPT_NOCACHE`` in order to disable caching. You may also change a number of variables (which name start with ``ZSH_THEME_GIT_PROMPT_``) to change the appearance of the prompt. Take a look in the file ``zshrc.sh`` to see how the function ``git_super_status`` is defined, and what variables are available.
#. Go in a git repository and test it!
**Enjoy!**
View
19 gitstatus.py
@@ -1,22 +1,29 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
+from __future__ import print_function
+
# change those symbols to whatever you prefer
symbols = {'ahead of': '', 'behind': '', 'prehash':':'}
from subprocess import Popen, PIPE
+import sys
gitsym = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE, stderr=PIPE)
branch, error = gitsym.communicate()
-if error.find('fatal: Not a git repository') != -1:
- import sys
+error_string = error.decode('utf-8')
+
+if 'fatal: Not a git repository' in error_string:
sys.exit(0)
branch = branch.strip()[11:]
-
-changed_files = [namestat[0] for namestat in Popen(['git','diff','--name-status'], stdout=PIPE).communicate()[0].splitlines()]
+res, err = Popen(['git','diff','--name-status'], stdout=PIPE, stderr=PIPE).communicate()
+err_string = err.decode('utf-8')
+if 'fatal' in err_string:
+ sys.exit(0)
+changed_files = [namestat[0] for namestat in res.splitlines()]
staged_files = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()]
nb_changed = len(changed_files) - changed_files.count('U')
nb_U = staged_files.count('U')
@@ -56,12 +63,12 @@
remote += '%s%s' % (symbols['ahead of'], ahead)
out = '\n'.join([
- branch,
+ branch.decode('ASCII'),
remote,
staged,
conflicts,
changed,
untracked,
clean])
-print out
+print(out)
View
3  zshrc.sh
@@ -25,7 +25,7 @@ function preexec_update_git_vars() {
}
function precmd_update_git_vars() {
- if [ -n "$__EXECUTED_GIT_COMMAND" ]; then
+ if [ -n "$__EXECUTED_GIT_COMMAND" ] || [ -n "$ZSH_THEME_GIT_PROMPT_NOCACHE" ]; then
update_current_git_vars
unset __EXECUTED_GIT_COMMAND
fi
@@ -52,6 +52,7 @@ function update_current_git_vars() {
git_super_status() {
+ precmd_update_git_vars
if [ -n "$__CURRENT_GIT_STATUS" ]; then
STATUS="($GIT_BRANCH"
STATUS="$ZSH_THEME_GIT_PROMPT_PREFIX$ZSH_THEME_GIT_PROMPT_BRANCH$GIT_BRANCH%{${reset_color}%}"

No commit comments for this range

Something went wrong with that request. Please try again.