summaryrefslogtreecommitdiff
path: root/polybar/playerctl.sh
diff options
context:
space:
mode:
Diffstat (limited to 'polybar/playerctl.sh')
-rwxr-xr-xpolybar/playerctl.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/polybar/playerctl.sh b/polybar/playerctl.sh
new file mode 100755
index 0000000..4646652
--- /dev/null
+++ b/polybar/playerctl.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+CONFIG="$HOME/.config/polybar/config.ini"
+color=$(awk '
+ $0 ~ /^\[module\/playerctl\]/ { in_section=1 }
+ in_section && $0 ~ /^label-foreground/ {
+ gsub(/[ \t]+/, "", $0); split($0, a, "="); print a[2]; exit
+ }
+' "$CONFIG")
+
+color=${color:-#ffffff} # fallback
+
+icon_color="%{F$color}"
+reset_color="%{F-}"
+
+playerctlstatus=$(playerctl status 2>/dev/null)
+song=$(playerctl metadata title 2>/dev/null)
+artist=$(playerctl metadata artist 2>/dev/null)
+
+if [[ -z "$playerctlstatus" ]]; then
+ echo ""
+elif [[ "$playerctlstatus" =~ "Playing" ]]; then
+ if [[ -z "$artist" ]]; then
+ echo "%{A1:playerctl pause:}$icon_color⏸️$reset_color $song%{A}"
+ else
+ echo "%{A1:playerctl pause:}$icon_color⏸️$reset_color $song%{A}"
+ fi
+else
+ echo "%{A1:playerctl play:}$icon_color▶️$reset_color $song%{A}"
+fi