diff --git a/bumblebee/modules/git.py b/bumblebee/modules/git.py index fb42a8e..468d174 100644 --- a/bumblebee/modules/git.py +++ b/bumblebee/modules/git.py @@ -23,50 +23,53 @@ import bumblebee.util class Module(bumblebee.engine.Module): def __init__(self, engine, config): - super(Module, self).__init__(engine, config, - bumblebee.output.Widget(full_text=self.gitinfo) - ) + widgets = [] + super(Module, self).__init__(engine, config, widgets) self._engine = engine - self._fmt = self.parameter("format", "{branch} {flags}") self._error = False + self.update(self.widgets()) def hidden(self): return self._error - def gitinfo(self, widget): - info = "" - directory = None - data = { - "branch": "n/a", - "directory": "n/a", - "flags": {}, - } + def update(self, widgets): + state = {} + new_widgets = [] try: directory = bumblebee.util.execute("xcwd").strip() directory = self._get_git_root(directory) repo = pygit2.Repository(directory) + new_widgets.append(bumblebee.output.Widget(name='git.main', full_text=repo.head.shorthand)) + 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 + state['new'] = True if flags == pygit2.GIT_STATUS_WT_DELETED or \ flags == pygit2.GIT_STATUS_INDEX_DELETED: - data["flags"]["deleted"] = True + state['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()]) + state['modified'] = True self._error = False + if 'new' in state: + new_widgets.append(bumblebee.output.Widget(name='git.new')) + if 'modified' in state: + new_widgets.append(bumblebee.output.Widget(name='git.modified')) + if 'deleted' in state: + new_widgets.append(bumblebee.output.Widget(name='git.deleted')) + + while len(widgets) > 0: + del widgets[0] + for widget in new_widgets: + widgets.append(widget) + except Exception as e: self._error = True - logging.error(e) - return "n/a" - return string.Formatter().vformat(self._fmt, (), data) + def state(self, widget): + return widget.name.split('.')[1] def _get_git_root(self, directory): while len(directory) > 1: diff --git a/screenshots/git.png b/screenshots/git.png index 2ec404b..69f786b 100644 Binary files a/screenshots/git.png and b/screenshots/git.png differ diff --git a/themes/gruvbox-light.json b/themes/gruvbox-light.json index 11ef684..ebb7983 100644 --- a/themes/gruvbox-light.json +++ b/themes/gruvbox-light.json @@ -49,5 +49,10 @@ "fg": "#1d2021", "bg": "#b8bb26" } - } + }, + "git": { + "modified": { "bg": "#458588" }, + "deleted": { "bg": "#9d0006" }, + "new": { "bg": "#b16286" } + } } diff --git a/themes/gruvbox-powerline-light.json b/themes/gruvbox-powerline-light.json index b4c4311..ba4b441 100644 --- a/themes/gruvbox-powerline-light.json +++ b/themes/gruvbox-powerline-light.json @@ -49,5 +49,10 @@ "fg": "#1d2021", "bg": "#b8bb26" } + }, + "git": { + "modified": { "bg": "#458588" }, + "deleted": { "bg": "#9d0006" }, + "new": { "bg": "#b16286" } } } diff --git a/themes/gruvbox-powerline.json b/themes/gruvbox-powerline.json index f4cee5d..1e0f588 100644 --- a/themes/gruvbox-powerline.json +++ b/themes/gruvbox-powerline.json @@ -49,5 +49,10 @@ "fg": "#1d2021", "bg": "#b8bb26" } + }, + "git": { + "modified": { "bg": "#458588" }, + "deleted": { "bg": "#9d0006" }, + "new": { "bg": "#b16286" } } } diff --git a/themes/gruvbox.json b/themes/gruvbox.json index 3f8df28..8ef2813 100644 --- a/themes/gruvbox.json +++ b/themes/gruvbox.json @@ -49,5 +49,10 @@ "fg": "#1d2021", "bg": "#b8bb26" } - } + }, + "git": { + "modified": { "bg": "#458588" }, + "deleted": { "bg": "#9d0006" }, + "new": { "bg": "#b16286" } + } } diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index 6cc79bb..42e78af 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -121,5 +121,11 @@ "ONLINE": {"prefix": "pool"}, "FAULTED": {"prefix": "pool (!)"}, "DEGRADED": {"prefix": "pool (!)"} + }, + "git": { + "main": { "prefix": "" }, + "new": { "prefix": "[n]" }, + "modified": { "prefix": "[m]" }, + "deleted": { "prefix": "[d]" } } } diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 01359da..83b5ac8 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -186,9 +186,9 @@ } }, "git": { - "prefix": "", - "new": "", - "modified": "", - "deleted": "" + "main": { "prefix": "" }, + "new": { "prefix": "" }, + "modified": { "prefix": "" }, + "deleted": { "prefix": "" } } } diff --git a/themes/solarized-dark-awesome.json b/themes/solarized-dark-awesome.json index 9c3a6b3..9ec45e2 100644 --- a/themes/solarized-dark-awesome.json +++ b/themes/solarized-dark-awesome.json @@ -40,5 +40,10 @@ "fg": "#002b36", "bg": "#859900" } - } + }, + "git": { + "modified": { "bg": "#2aa198" }, + "deleted": { "bg": "#d33682" }, + "new": { "bg": "#859900" } + } } diff --git a/themes/solarized-powerline.json b/themes/solarized-powerline.json index f940e5c..3e52f7f 100644 --- a/themes/solarized-powerline.json +++ b/themes/solarized-powerline.json @@ -42,5 +42,10 @@ "fg": "#002b36", "bg": "#859900" } - } + }, + "git": { + "modified": { "bg": "#2aa198" }, + "deleted": { "bg": "#d33682" }, + "new": { "bg": "#859900" } + } } diff --git a/themes/solarized.json b/themes/solarized.json index 03cabec..4486634 100644 --- a/themes/solarized.json +++ b/themes/solarized.json @@ -44,5 +44,10 @@ "fg": "#002b36", "bg": "#859900" } - } + }, + "git": { + "modified": { "bg": "#2aa198" }, + "deleted": { "bg": "#d33682" }, + "new": { "bg": "#859900" } + } }