From 5738aac1ceabc6f89ae4348972d0d897b094acf4 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 20 Jan 2019 14:43:27 +0100 Subject: [PATCH] [modules/git] Add some status icons Add icons for: * local modifications * local delete * local add --- bumblebee/modules/git.py | 22 +++++++++++++++++++++- bumblebee/theme.py | 3 +++ themes/icons/awesome-fonts.json | 7 ++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/git.py b/bumblebee/modules/git.py index 2bd8891..6070cd0 100644 --- a/bumblebee/modules/git.py +++ b/bumblebee/modules/git.py @@ -22,20 +22,40 @@ class Module(bumblebee.engine.Module): super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.gitinfo) ) - self._fmt = self.parameter("format", "{branch} - {directory}") + self._engine = engine + self._fmt = self.parameter("format", "{branch} {flags}") + + def hidden(self): + return False # TODO def gitinfo(self, widget): info = "" directory = None data = { "branch": "n/a", + "directory": "n/a", + "flags": {}, } try: directory = bumblebee.util.execute("xcwd").strip() directory = self._get_git_root(directory) repo = pygit2.Repository(directory) + + for filepath, flags in repo.status().items(): + if flags == pygit2.GIT_STATUS_WT_NEW or \ + flags == pygit2.GIT_STATUS_INDEX_NEW: + data["flags"]["new"] = True + if flags == pygit2.GIT_STATUS_WT_DELETED or \ + flags == pygit2.GIT_STATUS_INDEX_DELETED: + data["flags"]["deleted"] = True + if flags == pygit2.GIT_STATUS_WT_MODIFIED or \ + flags == pygit2.GIT_STATUS_INDEX_MODIFIED: + data["flags"]["modified"] = True + data["branch"] = repo.head.shorthand data["directory"] = directory + data["flags"] = " ".join([self._engine._theme.symbol(widget, name, name[0]) for name in data["flags"].keys()]) + except Exception as e: return e diff --git a/bumblebee/theme.py b/bumblebee/theme.py index e88e67c..e57d58d 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -115,6 +115,9 @@ class Theme(object): pre = self._get(widget, "prefix", None) return u"{}{}{}".format(padding, pre, padding) if pre else default + def symbol(self, widget, name, default=None): + return self._get(widget, name, default) + def suffix(self, widget, default=None): """Return the theme suffix for a widget's full text""" padding = self._get(widget, "padding", "") diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index d62c643..3ef4d7d 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -184,5 +184,10 @@ "copying": { "prefix": "" } - } + }, + "git": { + "added": "", + "modified": "", + "deleted": "" + } }