From 40ce35bd2f379f2c30e51173752926f8c620ffd6 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Mon, 10 May 2021 14:44:07 +0400 Subject: Changed window manager to bspwm and added custom config for lemonbar --- .local/bin/lemonbar/modules/updates.py | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .local/bin/lemonbar/modules/updates.py (limited to '.local/bin/lemonbar/modules/updates.py') diff --git a/.local/bin/lemonbar/modules/updates.py b/.local/bin/lemonbar/modules/updates.py new file mode 100644 index 0000000..67c8e93 --- /dev/null +++ b/.local/bin/lemonbar/modules/updates.py @@ -0,0 +1,48 @@ +from subprocess import run as _run +from time import time + + +def run(command): + return _run(command.split(), capture_output=True).stdout.decode().strip() + + +def pacman_count(): + cnt = 0 + for line in run('pacman -Qu').split("\n"): + if "[ignored]" not in line: + cnt += 1 + return cnt + + +def yay_count(): + cnt = 0 + for line in run('yay -Qau').split("\n"): + if "[ignored]" not in line: + cnt += 1 + return cnt + + +def callback(): + tmp_file = "/tmp/lemonbar/updates" + try: + with open(tmp_file) as f: + data = f.read().split() + except FileNotFoundError: + data = '' + + try: + timestamp = float(data[0]) + except (ValueError, IndexError): + timestamp = 0 + + if time() - timestamp > 900: + pacman = pacman_count() + aur = yay_count() + with open(tmp_file, "w") as f: + f.write(f"{time()} {pacman} {aur}") + else: + pacman = data[1] + aur = data[2] + + return f"UPD: {pacman}+{aur}" + -- cgit v1.2.3