configs/arch-config/scripts/polybar/player-cmus.sh

45 lines
1.4 KiB
Bash
Raw Normal View History

2020-11-24 10:13:15 +01:00
#!/bin/sh
# from https://github.com/polybar/polybar-scripts/tree/master/polybar-scripts/player-cmus
if info=$(cmus-remote -Q 2> /dev/null); then
status=$(echo "$info" | grep -v "set " | grep -v "tag " | grep "status " | cut -d ' ' -f 2)
if [ "$status" = "playing" ] || [ "$status" = "paused" ] || [ "$status" = "stopped" ]; then
title=$(echo "$info" | grep -v 'set ' | grep " title " | cut -d ' ' -f 3-)
artist=$(echo "$info" | grep -v 'set ' | grep " artist " | cut -d ' ' -f 3-)
position=$(echo "$info" | grep -v "set " | grep -v "tag " | grep "position " | cut -d ' ' -f 2)
duration=$(echo "$info" | grep -v "set " | grep -v "tag " | grep "duration " | cut -d ' ' -f 2)
if [ "$artist" ] || [ "$title" ]; then
if [ "$duration" -ge 0 ]; then
pos_minutes=$(printf "%02d" $((position / 60)))
pos_seconds=$(printf "%02d" $((position % 60)))
dur_minutes=$(printf "%02d" $((duration / 60)))
dur_seconds=$(printf "%02d" $((duration % 60)))
info_string="| $pos_minutes:$pos_seconds / $dur_minutes:$dur_seconds"
fi
info_string="$artist - $title $info_string"
if [ "$status" = "playing" ]; then
2020-11-24 12:48:21 +01:00
echo "$info_string"
2020-11-24 10:13:15 +01:00
elif [ "$status" = "paused" ]; then
2020-11-24 12:48:21 +01:00
echo "$info_string"
2020-11-24 10:13:15 +01:00
elif [ "$status" = "stopped" ]; then
2020-11-24 12:48:21 +01:00
echo "$info_string"
2020-11-24 10:13:15 +01:00
else
echo ""
fi
else
echo ""
fi
else
echo ""
fi
else
echo ""
fi