dotfiles/.i3blocks/mocp

74 lines
1.5 KiB
Text
Raw Normal View History

#!/bin/bash
2019-01-10 23:28:52 +01:00
if pidof mocp &>/dev/null
then
origstatus=$(mocp -Q "%state")
else
origstatus=STOP
[[ -n "$BLOCK_BUTTON" ]] && mocp -S
fi
case $BLOCK_BUTTON in
2019-01-10 23:28:52 +01:00
1) [[ "$origstatus" != "STOP" ]] && mocp -r || mocp -p ;;
2) mocp -G ;;
2019-01-10 23:28:52 +01:00
3) [[ "$origstatus" != "STOP" ]] && mocp -f || mocp -p ;;
4) mocp -j $(($(mocp -Q "%cs") - 5))s ;;
5) mocp -j $(($(mocp -Q "%cs") + 5))s ;;
esac
2019-01-10 23:28:52 +01:00
status="<span foreground=\"#6699CC\">?</span>"
case $origstatus in
STOP ) status="<span foreground=\"#F2777A\">■</span>" ;;
PAUSE ) status="<span foreground=\"#FFCC66\">∥</span>" ;;
PLAY ) status="<span foreground=\"#99CC99\">▶</span>" ;;
esac
2019-01-10 23:28:52 +01:00
if [[ "$origstatus" != "STOP" ]]
then
2019-01-10 23:28:52 +01:00
if [[ -f /dev/shm/mocp ]]
then
song=$(</dev/shm/mocp)
else
song=$(mocp -Q "%song")
[[ -z "$song" ]] && song=$(basename "$(mocp -Q %file)")
[[ -n "$song" ]] && echo "$song" > /dev/shm/mocp
fi
2019-01-10 23:28:52 +01:00
song="${song//&/and}"
2018-11-30 22:00:19 +01:00
2019-01-10 23:28:52 +01:00
if [ ${#song} -gt 30 ]
then
dots="…"
fi
if [ ${#song} -gt 15 ]
then
shortdots="…"
fi
time="$(mocp -Q "[%ct %tl %tt]")"
shorttime="$(mocp -Q "%ct %tl")"
if [[ "$time" = "[ ]" ]] || [[ -z "$time" ]]
then
time="[--:-- --:-- --:--]"
fi
if [[ -z "$shorttime" ]] || [[ "$shorttime" = " " ]]
then
shorttime="--:-- --:--"
fi
if [[ "${#shorttime}" -eq 6 ]]
then
shorttime="${shorttime}--:--"
fi
echo "$status ${song:0:30}$dots ${time/ ]/ --:-- --:--]}"
echo "$status ${song:0:15}$shortdots $shorttime"
else
[[ -f /dev/shm/mocp ]] && rm /dev/shm/mocp
echo "$status [--:-- --:-- --:--]"
echo "$status --:-- --:--"
fi