summaryrefslogtreecommitdiff
path: root/polybar/scripts/music-status.sh
diff options
context:
space:
mode:
authorDavid Moc <personal@cdatgoose.org>2026-05-24 11:48:07 +0200
committerDavid Moc <personal@cdatgoose.org>2026-05-24 11:48:07 +0200
commit5fb19f10389b70ee2389755106092a9ef6c64598 (patch)
tree969eb0466de581cb14aa09f751a95138620fc720 /polybar/scripts/music-status.sh
Go
Diffstat (limited to 'polybar/scripts/music-status.sh')
-rwxr-xr-xpolybar/scripts/music-status.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/polybar/scripts/music-status.sh b/polybar/scripts/music-status.sh
new file mode 100755
index 0000000..229e058
--- /dev/null
+++ b/polybar/scripts/music-status.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+if ! command -v playerctl >/dev/null 2>&1; then
+ echo "n/a"
+ exit 0
+fi
+
+status="$(playerctl status 2>/dev/null || true)"
+if [ -z "$status" ]; then
+ echo "off"
+ exit 0
+fi
+
+artist="$(playerctl metadata artist 2>/dev/null || true)"
+title="$(playerctl metadata title 2>/dev/null || true)"
+
+if [ -n "$artist" ] && [ -n "$title" ]; then
+ text="$artist - $title"
+elif [ -n "$title" ]; then
+ text="$title"
+else
+ text="$status"
+fi
+
+case "$status" in
+ Playing)
+ prefix="%{F#98971a}>%{F-}"
+ ;;
+ Paused)
+ prefix="%{F#d79921}=%{F-}"
+ ;;
+ *)
+ prefix="-"
+ ;;
+esac
+
+printf '%s %s\n' "$prefix" "$(printf '%s' "$text" | cut -c 1-32)"