From c9ca8e06d1cdc4e8621f94c3593f0eb840abfb8c Mon Sep 17 00:00:00 2001 From: XZS Date: Fri, 22 Apr 2016 14:50:07 +0200 Subject: [PATCH] provide stash counter Some version control systems have an area where changes can be stored as temporary work in progress instead publishing them to the history. This segment is intended to display their count, reminding the developer about open ends in the current repository. The underlying implementation is VCS-specific and has to be provided by the respective library module. --- powerline/segments/common/vcs.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/powerline/segments/common/vcs.py b/powerline/segments/common/vcs.py index 90e4e772..1aa5d110 100644 --- a/powerline/segments/common/vcs.py +++ b/powerline/segments/common/vcs.py @@ -56,3 +56,34 @@ branch = with_docstring(BranchSegment(), Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``. ''') + + +@requires_filesystem_watcher +@requires_segment_info +class StashSegment(Segment): + divider_highlight_group = None + + @staticmethod + def get_directory(segment_info): + return segment_info['getcwd']() + + def __call__(self, pl, segment_info, create_watcher): + name = self.get_directory(segment_info) + if name: + repo = guess(path=name, create_watcher=create_watcher) + if repo is not None: + stash = getattr(repo, 'stash', None) + if stash: + stashes = stash() + if stashes: + return [{ + 'contents': str(stashes), + 'highlight_groups': ['stash'], + 'divider_highlight_group': self.divider_highlight_group + }] + +stash = with_docstring(StashSegment(), +'''Return the number of current VCS stash entries, if any. + +Highlight groups used: ``stash``. +''')