2021-02-13 20:17:23 +01:00
|
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
|
|
######################################################################
|
2021-02-15 00:12:27 +01:00
|
|
|
|
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
|
2021-02-13 20:17:23 +01:00
|
|
|
|
# @file : sb-music
|
2021-02-15 00:37:34 +01:00
|
|
|
|
# @license : GPLv3
|
2021-02-13 20:17:23 +01:00
|
|
|
|
# @created : Saturday Feb 13, 2021 18:05:21 CET
|
|
|
|
|
#
|
|
|
|
|
# @description : music block for dwmblocks
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
|
|
|
2021-03-11 01:53:04 +01:00
|
|
|
|
unicode() { sed "s/[‘’]/'/g;s/[“”]/\"/g"; }
|
2021-02-20 19:07:30 +01:00
|
|
|
|
format() { sed "s/^volume:n\/a.*//g;/^volume:/d;s/\\&/&/g;s/\\[paused\\].*//g;s/\\[playing\\].*//g"; }
|
|
|
|
|
|
2021-02-13 20:17:23 +01:00
|
|
|
|
mpc="$(mpc --format "%albumartist% - %title%")"
|
2021-03-11 01:53:04 +01:00
|
|
|
|
title="$(echo "$mpc" | head -n1 | cut -d'-' -f2 | unicode)"
|
2021-02-20 19:07:30 +01:00
|
|
|
|
[ "$(echo "$title" | wc -c)" -gt 18 ] && title="$(printf "%.15s..." "$title")"
|
2021-03-11 01:53:04 +01:00
|
|
|
|
artist="$(echo "$mpc" | head -n1 | cut -d'-' -f1 | unicode)"
|
2021-02-20 19:07:30 +01:00
|
|
|
|
[ "$(echo "$artist" | wc -c)" -gt 18 ] && artist="$(printf "%.15s..." "$artist")"
|
|
|
|
|
status="$(echo "$mpc" | tail -n2 | format)"
|
2021-02-13 20:17:23 +01:00
|
|
|
|
|
|
|
|
|
pgrep -f sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 &
|
|
|
|
|
|
2021-03-11 13:12:42 +01:00
|
|
|
|
[ -n "$status" ] && printf " %s %s-%s " "$status" "$artist" "$title"
|