feat: do not display notification when make is not available
This commit is contained in:
parent
318467d0c6
commit
df0408c1fa
1 changed files with 20 additions and 15 deletions
|
@ -1,15 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2154
|
||||
NOTIFICATION_PROGRAM='mako
|
||||
'
|
||||
process_args() {
|
||||
while [ "$#" -ge 2 ]
|
||||
do
|
||||
while [ "$#" -ge 2 ]; do
|
||||
printf -v "$1" "%s" "$2"
|
||||
shift
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
escape() {
|
||||
local string
|
||||
string=$1
|
||||
|
@ -19,10 +19,17 @@ escape(){
|
|||
printf "%s" "$string"
|
||||
}
|
||||
|
||||
# Just quit this application if our notification program does not exist
|
||||
# With this notification will not be displayed on my work laptop. Avoid
|
||||
# notification pollution!
|
||||
check_notification_program() {
|
||||
if ! command -v "$NOTIFICATION_PROGRAM"; then
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
options=(--app-name=cmus --transient -u low)
|
||||
|
||||
filename=${file##*/}
|
||||
path=${file%/*}
|
||||
|
||||
|
@ -41,22 +48,19 @@ main() {
|
|||
fi
|
||||
title="<b>$title</b>"
|
||||
|
||||
if [ -n "$artist" ]
|
||||
then
|
||||
if [ -n "$artist" ]; then
|
||||
if [[ ${#artist} -gt 22 ]]; then
|
||||
artist="${artist:0:21}…"
|
||||
fi
|
||||
printf -v l_artist "<span size='x-large'>by </span>%s" "$(escape "$artist")"
|
||||
fi
|
||||
|
||||
if [ -n "$date" ]
|
||||
then
|
||||
if [ -n "$date" ]; then
|
||||
date="${date%%-*}"
|
||||
fi
|
||||
|
||||
# Get Album
|
||||
if [ -n "$album" ]
|
||||
then
|
||||
if [ -n "$album" ]; then
|
||||
if [[ ${#album} -gt 19 ]]; then
|
||||
album="${album:0:19}…"
|
||||
fi
|
||||
|
@ -65,8 +69,9 @@ main() {
|
|||
|
||||
printf -v l_intro "<span variant='small-caps'>cmus:<b>%s</b></span>" "$(escape "$status")"
|
||||
printf -v body "%s\n" "${l_intro:-}" "${title:-}" "${l_artist:-}" "${l_album:-}"
|
||||
notify-send "${options[@]}" "unseless" "$body"
|
||||
notify-send "${options[@]}" "useless" "$body"
|
||||
}
|
||||
|
||||
check_notification_program
|
||||
process_args "$@"
|
||||
main
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue