mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 21:41:07 +01:00
Pull in simplified version from @wkentaro
This version uses `git status --porcelain` instead of making multiple calls to `git status`.
This commit is contained in:
parent
6443626a6b
commit
5642014ff1
1 changed files with 42 additions and 38 deletions
|
@ -4,6 +4,7 @@ from __future__ import print_function
|
||||||
# change this symbol to whatever you prefer
|
# change this symbol to whatever you prefer
|
||||||
prehash = ':'
|
prehash = ':'
|
||||||
|
|
||||||
|
import subprocess
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
@ -17,20 +18,23 @@ if 'fatal: Not a git repository' in error_string:
|
||||||
|
|
||||||
branch = branch.decode("utf-8").strip()[11:]
|
branch = branch.decode("utf-8").strip()[11:]
|
||||||
|
|
||||||
res, err = Popen(['git','diff','--name-status'], stdout=PIPE, stderr=PIPE).communicate()
|
# Get git status (staged, change, conflicts and untracked)
|
||||||
err_string = err.decode('utf-8')
|
try:
|
||||||
if 'fatal' in err_string:
|
res = subprocess.check_output(['git', 'status', '--porcelain'])
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
changed_files = [namestat[0] for namestat in res.decode("utf-8").splitlines()]
|
status = [(st[0], st[1], st[2:]) for st in res.splitlines()]
|
||||||
staged_files = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()]
|
untracked, staged, changed, conflicts = [], [], [], []
|
||||||
nb_changed = len(changed_files) - changed_files.count('U')
|
for st in status:
|
||||||
nb_U = staged_files.count('U')
|
if st[0] == '?' and st[1] == '?':
|
||||||
nb_staged = len(staged_files) - nb_U
|
untracked.append(st)
|
||||||
staged = str(nb_staged)
|
else:
|
||||||
conflicts = str(nb_U)
|
if st[1] == 'M':
|
||||||
changed = str(nb_changed)
|
changed.append(st)
|
||||||
nb_untracked = len([0 for status in Popen(['git','status','--porcelain',],stdout=PIPE).communicate()[0].decode("utf-8").splitlines() if status.startswith('??')])
|
if st[0] == 'U':
|
||||||
untracked = str(nb_untracked)
|
conflicts.append(st)
|
||||||
|
elif st[0] != ' ':
|
||||||
|
staged.append(st)
|
||||||
|
|
||||||
ahead, behind = 0,0
|
ahead, behind = 0,0
|
||||||
|
|
||||||
|
@ -56,10 +60,10 @@ out = ' '.join([
|
||||||
branch,
|
branch,
|
||||||
str(ahead),
|
str(ahead),
|
||||||
str(behind),
|
str(behind),
|
||||||
staged,
|
str(len(staged)),
|
||||||
conflicts,
|
str(len(conflicts)),
|
||||||
changed,
|
str(len(changed)),
|
||||||
untracked,
|
str(len(untracked)),
|
||||||
])
|
])
|
||||||
print(out, end='')
|
print(out, end='')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue