diff --git a/home/config b/home/config index c77a6b7..bc01bb6 100644 --- a/home/config +++ b/home/config @@ -215,7 +215,7 @@ bar { # When the status_command prints a new line to stdout, swaybar updates. # The default just shows the current date and time. - status_command while date +'%Y-%m-%d %X'; do sleep 1; done + status_command ~/.config/sway/status colors { statusline #ffffff diff --git a/home/default.nix b/home/default.nix index 56298f0..15514f9 100644 --- a/home/default.nix +++ b/home/default.nix @@ -163,6 +163,7 @@ in }; home.file.".config/sway/config".source = ./config; + home.file.".config/sway/status".source = ./status; # Let Home Manager install and manage itself. programs.home-manager.enable = true; diff --git a/home/pkgs.nix b/home/pkgs.nix index 8c1657f..0fb833c 100644 --- a/home/pkgs.nix +++ b/home/pkgs.nix @@ -102,7 +102,10 @@ with pkgs; [ prusa-slicer pv pwgen - python3 + (python3.withPackages (python-pkgs: with python-pkgs; [ + pandas + requests + ])) ranger recipemd reptyr diff --git a/home/status b/home/status new file mode 100755 index 0000000..176467a --- /dev/null +++ b/home/status @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 + +import json +import sys +import time +import requests +import logging + +from datetime import datetime + +logger = logging.getLogger(__name__) + + +class Status: + def status(self): + return None + + +class Cat(Status): + index = 0 + + def status(self): + cat_width = 200 + index = self.index + catwalk = " " * (cat_width - index) + 1 * "🐈🏳️‍🌈" + " " * index + self.index = (index + 1) % cat_width + + return catwalk + + +class Space(Status): + backoff = 0 + c_status = None + + def status(self): + backoff = self.backoff + if self.backoff == 0: + self.update() + + return self.c_status + + def update(self): + spacestatus_url = "https://status.stratum0.org/status.json" + resp = requests.get(url=spacestatus_url) + self.backoff = (self.backoff + 1) % 120 + data = resp.json() + if data["isOpen"]: + since = datetime.strptime(data["since"], "%Y-%m-%dT%H:%M:%S.%f").strftime("%A at %H:%M") + spacestatus = f"Space is open since {since}" + else: + spacestatus = "Space is closed" + self.c_status = spacestatus + + +class Battery(Status): + capacity_file = open('/sys/class/power_supply/BAT0/capacity', 'r') + status_file = open('/sys/class/power_supply/BAT0/status', 'r') + + def status(self): + self.status_file.seek(0) + status = self.status_file.read().rstrip() + + self.capacity_file.seek(0) + capacity = self.capacity_file.read().rstrip() + + battery = f"{status} {capacity}%" + + return battery + + +class Time(Status): + def status(state): + return datetime.now().strftime("%Vth %A %H:%M") + + +def print_header(): + header = { + "version": 1, + "click_events": False, + } + print(json.dumps(header)) + print("[") + + +def run(interval, widgets): + print_header() + + while True: + body = [] + + for widget in widgets: + try: + status = widget.status() + except Exception as e: + logger.error(e) + if status: + body += {"full_text": f"{status}"}, + + print(json.dumps(body), ",", flush=True) + + ts = interval - (time.time() % interval) + time.sleep(ts) + + +if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) + + # Interval in seconds + interval = 1.0 + + widgets = [Cat(), Space(), Battery(), Time()] + + run(interval, widgets) diff --git a/nixos/gorgon/configuration.nix b/nixos/gorgon/configuration.nix index 85bb03d..e0268e2 100644 --- a/nixos/gorgon/configuration.nix +++ b/nixos/gorgon/configuration.nix @@ -128,6 +128,7 @@ in ghostscript smartmontools + dmenu grim # screenshot functionality slurp # screenshot functionality mako # notification system developed by swaywm maintainer