#!/bin/bash LONG=25 SHORT=10 human_time() { local seconds="$1" if [[ "$seconds" -lt 0 ]] then echo "--:--" return fi local minutes=$(( $seconds / 60 )) seconds=$(( $seconds % 60 )) if [[ "$minutes" -ge 90 ]] then printf "%5s\n" "${minutes}m" else printf "%02d:%02d\n" "$minutes" "$seconds" fi return } if ! systemctl --user is-active mpd &>/dev/null then origstatus='off' else origstatus="$(mpc status | sed -n '2p' | grep -Eo '^\[.*\]' | tr -d '[]')" [[ -z "$origstatus" ]] && origstatus='stop' fi case $BLOCK_BUTTON in 1) mpc -q prev ;; 2) mpc -q toggle ;; 3) mpc -q next ;; 4) mpc -q volume +2 ;; 5) mpc -q volume -2 ;; esac status="" case $origstatus in stop ) status="" ;; paused ) status="" ;; playing ) status="" ;; off ) status="" ;; esac if [[ "$origstatus" != "stop" ]] && [[ "$origstatus" != "off" ]] then if [[ ! -f /dev/shm/mpd ]] then mpc -f '[[%artist%§]%title%|[%file%]' current > /dev/shm/mpd fi song=$( /dev/shm/mpd-scroll song="$( /dev/shm/mpd-scroll fi fi time="$(echo -e 'status\nclose' | nc -U $MPD_HOST | grep time \ | cut -d' ' -f2)" time_elapsed=$(human_time "${time%:*}") time_total=$(human_time "${time#*:}") time_left=$(human_time "$(( ${time#*:} - ${time%:*} ))") longtime="[$time_elapsed $time_left ${time_total/00:00/--:--}]" shorttime="$time_elapsed $time_left" case $scrolling in long) longsong="${song} " shortsong="${song} " ;; short) longsong="$(" echo "${shortsong} $status$shorttime" else [[ -f /dev/shm/mpd ]] && rm /dev/shm/mpd [[ -f /dev/shm/mpd-scroll ]] && rm /dev/shm/mpd-scroll printf "%${LONG}s $status[--:-- --:-- --:--]\n" " " printf "%${SHORT}s $status--:-- --:--\n" " " fi