dotfiles/polybar/.config/polybar/scripts/poly-mprisdisplay

48 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# script to echo the current playback situation
#
# call without args to return playing symbol or empty, depending on current playback status
# call with 1 to return 'artist - title' metadata (verbose mode)
# send SIGUSR2 signal to toggle pause/playing state of song (e.g. kill -USR2 %PID)
#
# depends on playerctl being installed
exist playerctl low "polybar music" || exit 1
mode=${1:-0}
update_time=1
symbol_playing=""
symbol_paused=""
modetoggle() {
mode=$(((mode + 1) % 2))
}
trap "modetoggle" USR1
playpause() {
playerctl play-pause
}
trap "playpause" USR2
decorate() {
if [ "$player_status" = "Playing" ]; then
echo "${symbol_playing}$1"
elif [ "$player_status" = "Paused" ]; then
echo "${symbol_paused}$1"
else
echo ""
fi
}
while true; do
player_status=$(playerctl status 2>/dev/null)
if [ $mode -eq 0 ]; then
decorate ""
elif [ $mode -eq 1 ]; then
decorate " $(playerctl metadata artist) - $(playerctl metadata title)"
fi
sleep $update_time &
wait
done