diff options
| author | George Abbott <george@gabbott.dev> | 2023-10-31 17:54:07 +0000 | 
|---|---|---|
| committer | George Abbott <george@gabbott.dev> | 2023-10-31 17:54:07 +0000 | 
| commit | 4d0bd914e7c1ee65f4036e60149a7b891906a5d3 (patch) | |
| tree | c2a6751823e064e003cd4f6166df07bfc106d7eb /sys/dwmblocks-mpc | |
Commit all to date.
Diffstat (limited to 'sys/dwmblocks-mpc')
| -rwxr-xr-x | sys/dwmblocks-mpc | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/sys/dwmblocks-mpc b/sys/dwmblocks-mpc new file mode 100755 index 0000000..0897855 --- /dev/null +++ b/sys/dwmblocks-mpc @@ -0,0 +1,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" | 
