From eaeed6ab5bca4ed529e60befa60aef22d4f9bb3f Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Sat, 8 May 2021 22:22:08 +0200 Subject: [PATCH] waybar: add calendar with khal, fmt formatting --- bin/waybar_khal.py | 37 +++++++++++++++++++++++++++++++++++++ waybar.d/config | 33 +++++++++++++++++++++------------ waybar.d/config_annoyance | 33 +++++++++++++++++++++------------ waybar.d/style.css | 4 ++-- 4 files changed, 81 insertions(+), 26 deletions(-) create mode 100755 bin/waybar_khal.py diff --git a/bin/waybar_khal.py b/bin/waybar_khal.py new file mode 100755 index 0000000..089e4e3 --- /dev/null +++ b/bin/waybar_khal.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +import subprocess +import datetime +import json +from html import escape + +data = {} + +today = datetime.date.today().strftime("%Y-%m-%d") +days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Today", + "Tomorrow" ] + +next_week = (datetime.date.today() + datetime.timedelta(days=10)).strftime("%Y-%m-%d") + +output = subprocess.check_output("khal list --format \"{title}\" now "+next_week, shell=True) +output = output.decode("utf-8") + +lines = output.split("\n") +new_lines = [] +for line in lines: + clean_line = escape(line).split(" ::")[0] + # bold headers + if len(clean_line) and clean_line.split(",")[0] in days: + clean_line = f"\n{clean_line}" + new_lines.append(clean_line) +output = "\n".join(new_lines).strip() + +today_text = datetime.date.today().strftime("%a, %d %b") +if today in output: + event = output.split('\n')[1] + data['text'] = f" {today_text}: {event}" +else: + data['text'] = f" {today_text}" + +data['tooltip'] = output + +print(json.dumps(data)) diff --git a/waybar.d/config b/waybar.d/config index f9047ba..0d436e2 100644 --- a/waybar.d/config +++ b/waybar.d/config @@ -30,6 +30,7 @@ "custom/separator#right", "battery", "custom/separator#right", + "custom/calendar", "clock", "tray" ], @@ -39,6 +40,16 @@ "custom/separator#right": { "format": " " }, + "custom/calendar": { + "format": "{}", + "tooltip-format": "{}", + "tooltip": true, + "return-type": "json", + "interval": 300, + "escape": false, + "exec": "$HOME/.config/sway/bin/waybar_khal.py 2> /dev/null", + "on-click": "foot -T float khal interactive" + }, "custom/mail": { "format": "{icon} {}", "return-type": "json", @@ -60,21 +71,19 @@ "format-icons": { "chromium": " ", "firefox": " ", - "Plexamp": "", - "default": " " + "Plexamp": " ", + "default": "♫ " }, "escape": true, "exec": "$HOME/.config/sway/bin/waybar_mediaplayer.py 2> /dev/null", "exec-if": "pgrep plexamp" }, "clock": { - "format": "{:%a, %d %b %H:%M}", - "tooltip-format": "{:%Y %B}\n{calendar}", + "format": "{:%H:%M}", "on-click": "foot -T float khal interactive" - }, "cpu": { - "format": " {usage}%", + "format": " {usage:3}%", "states": { "warning": 70, "critical": 90 @@ -90,7 +99,7 @@ "on-click": "foot -T float bashtop" }, "backlight": { - "format": "{icon} {percent}%", + "format": "{icon} {percent:3}%", "format-icons": [""] }, "battery": { @@ -100,15 +109,15 @@ "warning": 30, "critical": 15 }, - "format": "{icon} {capacity}%", - "format-charging": " {capacity}%", + "format": "{icon} {capacity:3}%", + "format-charging": " {capacity:3}%", "format-icons": ["", "", "", "", ""] }, "network#wl0": { "interval": 2, "interface": "wl0", "format": "{ifname}", - "format-wifi": "{ifname} {essid} ({signalStrength}%)", + "format-wifi": "{ifname} {essid} ({signalStrength:3}%)", "format-ethernet": "{ifname}", "format-linked": "{ifname}", "format-disconnected": "{ifname}", @@ -121,7 +130,7 @@ "interval": 2, "interface": "en0", "format": "{ifname}", - "format-wifi": " {essid} ({signalStrength}%)", + "format-wifi": " {essid} ({signalStrength:3}%)", "format-ethernet": "{ifname}", "format-linked": "{ifname}", "format-disconnected": "{ifname}", @@ -134,7 +143,7 @@ "interval": 2, "interface": "vpn0", "format": "{ifname}", - "format-wifi": " {essid} ({signalStrength}%)", + "format-wifi": " {essid} ({signalStrength:3}%)", "format-ethernet": "{ifname}", "format-linked": "{ifname}", "format-disconnected": "{ifname}", diff --git a/waybar.d/config_annoyance b/waybar.d/config_annoyance index e5c92b7..9f0157a 100644 --- a/waybar.d/config_annoyance +++ b/waybar.d/config_annoyance @@ -27,6 +27,7 @@ "custom/separator#right", "backlight", "custom/separator#right", + "custom/calendar", "clock", "tray" ], @@ -36,6 +37,16 @@ "custom/separator#right": { "format": " " }, + "custom/calendar": { + "format": "{}", + "tooltip-format": "{}", + "tooltip": true, + "return-type": "json", + "interval": 300, + "escape": false, + "exec": "$HOME/.config/sway/bin/waybar_khal.py 2> /dev/null", + "on-click": "foot -T float khal interactive" + }, "custom/mail": { "format": "{icon} {}", "return-type": "json", @@ -57,21 +68,19 @@ "format-icons": { "chromium": " ", "firefox": " ", - "Plexamp": "", - "default": " " + "Plexamp": " ", + "default": "♫ " }, "escape": true, "exec": "$HOME/.config/sway/bin/waybar_mediaplayer.py 2> /dev/null", "exec-if": "pgrep plexamp" }, "clock": { - "format": "{:%a, %d %b %H:%M}", - "tooltip-format": "{:%Y %B}\n{calendar}", + "format": "{:%H:%M}", "on-click": "foot -T float khal interactive" - }, "cpu": { - "format": " {usage}%", + "format": " {usage:3}%", "states": { "warning": 70, "critical": 90 @@ -87,7 +96,7 @@ "on-click": "foot -T float bashtop" }, "backlight": { - "format": "{icon} {percent}%", + "format": "{icon} {percent:3}%", "format-icons": [""] }, "battery": { @@ -97,15 +106,15 @@ "warning": 30, "critical": 15 }, - "format": "{icon} {capacity}%", - "format-charging": " {capacity}%", + "format": "{icon} {capacity:3}%", + "format-charging": " {capacity:3}%", "format-icons": ["", "", "", "", ""] }, "network#wl0": { "interval": 2, "interface": "wl0", "format": "{ifname}", - "format-wifi": "{ifname} {essid} ({signalStrength}%)", + "format-wifi": "{ifname} {essid} ({signalStrength:3}%)", "format-ethernet": "{ifname}", "format-linked": "{ifname}", "format-disconnected": "{ifname}", @@ -118,7 +127,7 @@ "interval": 2, "interface": "en0", "format": "{ifname}", - "format-wifi": " {essid} ({signalStrength}%)", + "format-wifi": " {essid} ({signalStrength:3}%)", "format-ethernet": "{ifname}", "format-linked": "{ifname}", "format-disconnected": "{ifname}", @@ -131,7 +140,7 @@ "interval": 2, "interface": "vpn0", "format": "{ifname}", - "format-wifi": " {essid} ({signalStrength}%)", + "format-wifi": " {essid} ({signalStrength:3}%)", "format-ethernet": "{ifname}", "format-linked": "{ifname}", "format-disconnected": "{ifname}", diff --git a/waybar.d/style.css b/waybar.d/style.css index 10ad694..ddab16a 100644 --- a/waybar.d/style.css +++ b/waybar.d/style.css @@ -9,8 +9,8 @@ * { border: none; border-radius: 0; - font-family: Input, "Font Awesome 5 Free"; - font-size: 13px; + font-family: "Cascadia Code PL Regular"; + font-size: 12px; min-height: 0; }