blob: 08978558f0c39330de49af9987a5ed95ed466d37 (
plain) (
blame)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 | #!/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"
 |