Created
June 2, 2021 20:42
-
-
Save 0x6d64/1532cf7dc9e5289d2c43805609f37f7c to your computer and use it in GitHub Desktop.
custom powerline segment that shows number of not synced edits in taskwarrior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
custom powerline segment that shows number of not synced edits in taskwarrior | |
created by https://github.com/0x6d64 | |
see also doc at https://github.com/b-ryan/powerline-shell | |
""" | |
import os | |
from powerline_shell.utils import BasicSegment, RepoStats | |
taskwarrior_basedir = os.path.expanduser("~/.task") | |
class Segment(BasicSegment): | |
"""Segment for taskwarrior not synced change count""" | |
symbol = RepoStats.symbols.get("changed") | |
@staticmethod | |
def get_sync_backlog_count(): | |
"""return number of not synced changes or None for fail""" | |
backlog_file = os.path.join(taskwarrior_basedir, "backlog.data") | |
backlog_count = None | |
if os.path.isfile(backlog_file): | |
with open(backlog_file, "r") as backlog_fp: | |
content = backlog_fp.readlines() | |
backlog_count = len(content) - 1 | |
if backlog_count < 0: | |
backlog_count = None | |
return backlog_count | |
def add_to_powerline(self): | |
"""add edit count to output""" | |
backlog_count = self.get_sync_backlog_count() | |
if backlog_count: | |
if backlog_count <= 2: | |
output = "tw{}".format(backlog_count * self.symbol) | |
else: | |
output = "tw{sym}{count}".format(count=backlog_count, sym=self.symbol) | |
self.powerline.append(output, self.powerline.theme.REPO_DIRTY_FG, | |
self.powerline.theme.REPO_DIRTY_BG) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment