Permalink
Browse files

Git status summary in statusbar

Essentially a merge of pull 188, but rewritten a bit. The request
didn't distinguish between the index and working copy, and missed
a few statuses.
  • Loading branch information...
1 parent 5e9696c commit c852894ab7a457cf16492be9af8395dd6248791a @kemayo committed Sep 14, 2012
Showing with 39 additions and 0 deletions.
  1. +3 −0 Git.sublime-settings
  2. +36 −0 statusbar.py
View
@@ -36,4 +36,7 @@
// statusbar
,"statusbar_branch": true
+ // Symbols for quick git status in status bar
+ ,"statusbar_status": true
+ ,"statusbar_status_symbols" : {"modified": "", "added": "+", "deleted": "×", "untracked": "?", "conflicts": "", "renamed":"R", "copied":"C", "clean": "", "separator": " "}
}
View
@@ -7,6 +7,9 @@ class GitBranchStatusListener(sublime_plugin.EventListener):
def on_activated(self, view):
view.run_command("git_branch_status")
+ def on_post_save(self, view):
+ view.run_command("git_branch_status")
+
class GitBranchStatusCommand(GitTextCommand):
def run(self, view):
@@ -15,6 +18,39 @@ def run(self, view):
self.run_command(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], self.branch_done, show_status=False)
else:
self.view.set_status("git-branch", "")
+ if (s.get("statusbar_status")):
+ self.run_command(['git', 'status', '--porcelain'], self.status_done, show_status=False)
+ else:
+ self.view.set_status("git-status", "")
def branch_done(self, result):
self.view.set_status("git-branch", "git branch: " + result.strip())
+
+ def status_done(self, result):
+ lines = [line for line in result.splitlines() if not (line.startswith("warning:") or line.startswith("The file"))]
+ index = [line[0] for line in lines if not line[0].isspace()]
+ working = [line[1] for line in lines if not line[1].isspace()]
+ self.view.set_status("git-status-index", "index: " + self.status_string(index))
+ self.view.set_status("git-status-working", "working: " + self.status_string(working))
+
+ def status_string(self, statuses):
+ s = sublime.load_settings("Git.sublime-settings")
+ symbols = s.get("statusbar_status_symbols")
+ if not statuses:
+ return symbols['clean']
+ status = []
+ if statuses.count('M'):
+ status.append("%d%s" % (statuses.count('M'), symbols['modified']))
+ if statuses.count('A'):
+ status.append("%d%s" % (statuses.count('A'), symbols['added']))
+ if statuses.count('D'):
+ status.append("%d%s" % (statuses.count('D'), symbols['deleted']))
+ if statuses.count('?'):
+ status.append("%d%s" % (statuses.count('?'), symbols['untracked']))
+ if statuses.count('U'):
+ status.append("%d%s" % (statuses.count('U'), symbols['conflicts']))
+ if statuses.count('R'):
+ status.append("%d%s" % (statuses.count('R'), symbols['renamed']))
+ if statuses.count('C'):
+ status.append("%d%s" % (statuses.count('C'), symbols['copied']))
+ return symbols['separator'].join(status)

0 comments on commit c852894

Please sign in to comment.