From 280b1691c2799986f56e740e744037f52a397ac6 Mon Sep 17 00:00:00 2001
From: Luca Bilke <luca@bil.ke>
Date: Wed, 9 Oct 2024 15:22:25 +0200
Subject: [PATCH] sb-task: new script

---
 common/.local/libexec/statusbar/sb-task | 26 +++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100755 common/.local/libexec/statusbar/sb-task

diff --git a/common/.local/libexec/statusbar/sb-task b/common/.local/libexec/statusbar/sb-task
new file mode 100755
index 00000000..946a8cae
--- /dev/null
+++ b/common/.local/libexec/statusbar/sb-task
@@ -0,0 +1,26 @@
+#!/bin/sh
+. libsb
+
+icon=󰄵
+
+get_context() {
+	task context show | awk "NR==1 { gsub(\"'\", \"\"); print \$2 }"
+}
+
+get_active() {
+	num_active=$(task export active | jq length)
+
+	[ "$num_active" = 0 ] && {
+		echo "No active task"
+		return
+	}
+
+	[ "$num_active" -gt 1 ] && {
+		echo "$num_active active tasks"
+		return
+	}
+
+	task export active | jq -r '.[0].description'
+}
+
+printf "%s %s: %s\n" "$icon" "$(get_context)" "$(get_active)"