diff --git a/lefthook.yaml b/lefthook.yaml index d1369fa..4410eea 100644 --- a/lefthook.yaml +++ b/lefthook.yaml @@ -1,11 +1,14 @@ +--- skip_output: [meta, success] no_tty: true + commit-msg: commands: lint:convco: run: cat {1} | convco check --from-stdin lint:typos: run: cat {1} | typos - + pre-commit: parallel: false commands: @@ -13,10 +16,11 @@ pre-commit: run: typos {staged_files} shellcheck: glob: "*.sh" - run: shellcheck {staged_files} + run: shellcheck {staged_files} shfmt: glob: "*.sh" - run: shfmt -d -ln bash -i 2 {staged_files} + run: shfmt -d -ln bash -i 4 {staged_files} + pre-push: parallel: false commands: diff --git a/modules/home-manager/audio/cmus/files/notify.sh b/modules/home-manager/audio/cmus/files/notify.sh index afc5b1d..f22f261 100755 --- a/modules/home-manager/audio/cmus/files/notify.sh +++ b/modules/home-manager/audio/cmus/files/notify.sh @@ -3,73 +3,73 @@ NOTIFICATION_PROGRAM='mako' process_args() { - while [ "$#" -ge 2 ]; do - printf -v "$1" "%s" "$2" - shift - shift - done + 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" + local string + string=$1 + string=${string//"<"/"<"} + string=${string//">"/">"} + string=${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 + if ! command -v "$NOTIFICATION_PROGRAM"; then + exit 0 + fi } main() { - options=(--app-name=cmus --transient -u low) - filename=${file##*/} - path=${file%/*} + options=(--app-name=cmus --transient -u low) + filename=${file##*/} + path=${file%/*} - if [[ -f "${path}/cover.png" ]]; then - options+=(-i "${path}/cover.png") - fi - - if [[ -f "${path}/cover.jpg" ]]; then - options+=(-i "${path}/cover.jpg") - fi - - ## Get title or filename - title=${title:-$filename} - if [[ ${#title} -gt 25 ]]; then - title="${title:0:24}…" - fi - title="$(escape "$title")" - - if [ -n "$artist" ]; then - if [[ ${#artist} -gt 22 ]]; then - artist="${artist:0:21}…" + if [[ -f "${path}/cover.png" ]]; then + options+=(-i "${path}/cover.png") 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}…" + if [[ -f "${path}/cover.jpg" ]]; then + options+=(-i "${path}/cover.jpg") 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[@]}" "useless" "$body" + ## 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[@]}" "useless" "$body" } check_notification_program