Browse Source

attempts to replace bash-git-prompt with something simpler and faster

master
Von Random 6 years ago
parent
commit
cf2627c699
  1. 34
      git_status.py

34
git_status.py

@ -0,0 +1,34 @@
#!/usr/bin/python3
import os
import pygit2
def test_status(num, stat_key):
if num & stat_key:
return 1
else:
return 0
if os.path.isdir(".git"):
repo = pygit2.Repository(".git")
files = repo.status()
staged = 0
unstaged = 0
confl = 0
for filename in files:
staged += test_status(files[filename], pygit2.GIT_STATUS_INDEX_NEW)
staged += test_status(files[filename], pygit2.GIT_STATUS_INDEX_DELETED)
staged += test_status(files[filename], pygit2.GIT_STATUS_INDEX_MODIFIED)
unstaged += test_status(files[filename], pygit2.GIT_STATUS_WT_NEW)
unstaged += test_status(files[filename], pygit2.GIT_STATUS_WT_DELETED)
unstaged += test_status(files[filename], pygit2.GIT_STATUS_WT_MODIFIED)
confl += test_status(files[filename], pygit2.GIT_STATUS_CONFLICTED)
result = str()
if staged > 0:
result += 's' + str(staged)
if unstaged > 0:
result += '+' + str(unstaged)
if confl > 0:
result += 'x' + str(confl)
if not result:
result += '.'
print(result)
Loading…
Cancel
Save