#!/bin/env python ### Add to ~/.config/waybar/config like so # "custom/xbps-updates": { # "format": "{}  ", # "interval": 3600, # "return-type": "json", # "exec": "xbps-checkup-updates | jq --unbuffered --compact-output", # "tooltip": true, # } import json from typing import NamedTuple ## updated with hourly cronjob that contains: # xbps-install -S # xbps-checkvers -I > /tmp/xbps_updates_available ## output is formatted like: # pkg name old_ver new_ver name again? random question mark?? # minizip 1.2.13_1 1.3_1 minizip ? UPDATE_FILE = "/tmp/xbps_updates_available" class Update(NamedTuple): package: str current_ver: str new_ver: str def __str__(self) -> str: return f"{self.package}: {self.current_ver} -> {self.new_ver}" def main(): output = { "text": "", "alt": "", "tooltip": "", "percentage": "", } updates = [] # get list of updates from UPDATE_FILE with open(UPDATE_FILE) as file: for line in file: split_line = line.split(" ") updates.append(Update(split_line[0], split_line[1], split_line[2])) num_updates = len(updates) # format updates for waybar output["text"] = str(num_updates) if num_updates <= 0: output["tooltip"] = "Up to date!" else: output["tooltip"] = f"Updates available:\n{'\n'.join(str(x) for x in updates)}" output["alt"] = f"Updates: {num_updates}" output["percentage"] = "0" print(json.dumps(output)) if __name__ == "__main__": main()