#!/usr/bin/env bash
# shellcheck disable=SC2154
process_args() {
while [ "$#" -ge 2 ]
do
printf -v "$1" "%s" "$2"
shift
shift
done
}
#
escape(){
local string
string=$1
string=${string//"<"/"<"}
string=${string//">"/">"}
string=${string//"&"/"&"}
printf "%s" "$string"
}
main() {
options=( --app-name=cmus --transient -u low)
filename=${file##*/}
image=${file%/*}/cover.jpg
if [[ -f "$image" ]]; then
options+=( -i "${image}" )
fi
## Get title or filename
title=${title:-$filename}
if [[ ${#title} -gt 25 ]]; then
title="${title:0:24}…"
fi
title="$title"
if [ -n "$artist" ]
then
if [[ ${#artist} -gt 22 ]]; then
artist="${artist:0:21}…"
fi
printf -v l_artist "by %s" "$(escape "$artist")"
fi
if [ -n "$date" ]
then
date="${date%%-*}"
fi
# Get Album
if [ -n "$album" ]
then
if [[ ${#album} -gt 19 ]]; then
album="${album:0:19}…"
fi
printf -v l_album "on %-20s %s" "$(escape "$album")" "${date:-}"
fi
printf -v l_intro "cmus:%s" "$(escape "$status")"
printf -v body "%s\n" "${l_intro:-}" "${title:-}" "${l_artist:-}" "${l_album:-}"
notify-send "${options[@]}" "unseless" "$body"
}
process_args "$@"
main