Skip to content

Instantly share code, notes, and snippets.

@0x6d64
Created June 2, 2021 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x6d64/1532cf7dc9e5289d2c43805609f37f7c to your computer and use it in GitHub Desktop.
Save 0x6d64/1532cf7dc9e5289d2c43805609f37f7c to your computer and use it in GitHub Desktop.
custom powerline segment that shows number of not synced edits in taskwarrior
"""
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