Compare commits
No commits in common. "8d237b21d273d6e7f67f01b4f56e40d895271d29" and "318467d0c693600eda61b8c2dcac26c586a196d4" have entirely different histories.
8d237b21d2
...
318467d0c6
2 changed files with 15 additions and 21 deletions
|
@ -30,7 +30,6 @@ in {
|
||||||
name = "nixfiles";
|
name = "nixfiles";
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
pkgs.shellcheck
|
pkgs.shellcheck
|
||||||
pkgs.shfmt
|
|
||||||
pkgs.lefthook
|
pkgs.lefthook
|
||||||
pkgs.go-task
|
pkgs.go-task
|
||||||
pkgs.convco
|
pkgs.convco
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
NOTIFICATION_PROGRAM='mako
|
|
||||||
'
|
|
||||||
process_args() {
|
process_args() {
|
||||||
while [ "$#" -ge 2 ]; do
|
while [ "$#" -ge 2 ]
|
||||||
|
do
|
||||||
printf -v "$1" "%s" "$2"
|
printf -v "$1" "%s" "$2"
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
escape() {
|
#
|
||||||
|
escape(){
|
||||||
local string
|
local string
|
||||||
string=$1
|
string=$1
|
||||||
string=${string//"<"/"<"}
|
string=${string//"<"/"<"}
|
||||||
|
@ -19,26 +19,19 @@ escape() {
|
||||||
printf "%s" "$string"
|
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() {
|
main() {
|
||||||
options=(--app-name=cmus --transient -u low)
|
options=( --app-name=cmus --transient -u low)
|
||||||
|
|
||||||
filename=${file##*/}
|
filename=${file##*/}
|
||||||
path=${file%/*}
|
path=${file%/*}
|
||||||
|
|
||||||
if [[ -f "${path}/cover.png" ]]; then
|
if [[ -f "${path}/cover.png" ]]; then
|
||||||
options+=(-i "${path}/cover.png")
|
options+=( -i "${path}/cover.png" )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f "${path}/cover.jpg" ]]; then
|
if [[ -f "${path}/cover.jpg" ]]; then
|
||||||
options+=(-i "${path}/cover.jpg")
|
options+=( -i "${path}/cover.jpg" )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Get title or filename
|
## Get title or filename
|
||||||
|
@ -48,19 +41,22 @@ main() {
|
||||||
fi
|
fi
|
||||||
title="<b>$title</b>"
|
title="<b>$title</b>"
|
||||||
|
|
||||||
if [ -n "$artist" ]; then
|
if [ -n "$artist" ]
|
||||||
|
then
|
||||||
if [[ ${#artist} -gt 22 ]]; then
|
if [[ ${#artist} -gt 22 ]]; then
|
||||||
artist="${artist:0:21}…"
|
artist="${artist:0:21}…"
|
||||||
fi
|
fi
|
||||||
printf -v l_artist "<span size='x-large'>by </span>%s" "$(escape "$artist")"
|
printf -v l_artist "<span size='x-large'>by </span>%s" "$(escape "$artist")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$date" ]; then
|
if [ -n "$date" ]
|
||||||
|
then
|
||||||
date="${date%%-*}"
|
date="${date%%-*}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get Album
|
# Get Album
|
||||||
if [ -n "$album" ]; then
|
if [ -n "$album" ]
|
||||||
|
then
|
||||||
if [[ ${#album} -gt 19 ]]; then
|
if [[ ${#album} -gt 19 ]]; then
|
||||||
album="${album:0:19}…"
|
album="${album:0:19}…"
|
||||||
fi
|
fi
|
||||||
|
@ -69,9 +65,8 @@ main() {
|
||||||
|
|
||||||
printf -v l_intro "<span variant='small-caps'>cmus:<b>%s</b></span>" "$(escape "$status")"
|
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:-}"
|
printf -v body "%s\n" "${l_intro:-}" "${title:-}" "${l_artist:-}" "${l_album:-}"
|
||||||
notify-send "${options[@]}" "useless" "$body"
|
notify-send "${options[@]}" "unseless" "$body"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_notification_program
|
|
||||||
process_args "$@"
|
process_args "$@"
|
||||||
main
|
main
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue