diff options
| author | anand <anand.panchdhari@gmail.com> | 2025-12-17 15:57:55 +0530 |
|---|---|---|
| committer | anand <anand.panchdhari@gmail.com> | 2025-12-17 15:57:55 +0530 |
| commit | b7ef29a8886a57aadb787807a7c6cf74c1f0ed3a (patch) | |
| tree | 366a68240fbc9da6b1d567bd6c46d1350ad814de /polybar/playerctl.sh | |
Nixos
Diffstat (limited to 'polybar/playerctl.sh')
| -rwxr-xr-x | polybar/playerctl.sh | 30 |
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 |
