#!/bin/bash # Accepts, e.g. 81:50 and prints it to 1:21:50. to_hms_time() { min="$(cut -d':' -f1 <<<"$1")" sec="$(cut -d':' -f2 <<<"$1")" ((hour=$min/60)) ((min=$min-$hour*60)) printf -v min "%02d" $min printf -v sec "%02d" $sec if [ $hour = "0" ] ; then printf "$min:$sec" else printf "$hour:$min:$sec" fi } FILENAME="$(mpc current -f "%title%")" if [ -z "$FILENAME" ] ; then FILENAME="$(basename "$(mpc current -f "%file%")")" # TODO: also remove file extension. fi TIMES="$(mpc status "%currenttime%/%totaltime%")" if [ -z "$FILENAME" ] && [ "$TIMES" = "0:00/0:00" ] ; then printf "" exit fi mpctime="$(mpc status %currenttime%/%totaltime%)" curtime="$(to_hms_time $(cut -d '/' -f1 <<<"$mpctime"))" # <<< isn't POSIX? tottime="$(to_hms_time $(cut -d '/' -f2 <<<"$mpctime"))" printf " %s/%s ~ %s" "$curtime" "$tottime" "$FILENAME"