From df0408c1fae0cb6f68ad719422498a7c38befb57 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Tue, 24 Sep 2024 10:24:53 +0200 Subject: [PATCH 1/2] feat: do not display notification when make is not available --- .../home-manager/audio/cmus/files/notify.sh | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/modules/home-manager/audio/cmus/files/notify.sh b/modules/home-manager/audio/cmus/files/notify.sh index a01bcfd..2116792 100755 --- a/modules/home-manager/audio/cmus/files/notify.sh +++ b/modules/home-manager/audio/cmus/files/notify.sh @@ -1,16 +1,16 @@ #!/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(){ +escape() { local string string=$1 string=${string//"<"/"<"} @@ -19,19 +19,26 @@ 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) - + options=(--app-name=cmus --transient -u low) filename=${file##*/} path=${file%/*} if [[ -f "${path}/cover.png" ]]; then - options+=( -i "${path}/cover.png" ) + options+=(-i "${path}/cover.png") fi if [[ -f "${path}/cover.jpg" ]]; then - options+=( -i "${path}/cover.jpg" ) + options+=(-i "${path}/cover.jpg") fi ## Get title or filename @@ -41,22 +48,19 @@ main() { fi title="$title" - if [ -n "$artist" ] - then + 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 + 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 "cmus:%s" "$(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 From 8d237b21d273d6e7f67f01b4f56e40d895271d29 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Tue, 24 Sep 2024 10:26:22 +0200 Subject: [PATCH 2/2] build: install shfmt on dev-shell --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 2570513..6549eb4 100644 --- a/flake.nix +++ b/flake.nix @@ -30,6 +30,7 @@ in { name = "nixfiles"; buildInputs = [ pkgs.shellcheck + pkgs.shfmt pkgs.lefthook pkgs.go-task pkgs.convco