38e80e9f21ee981b5f616003c788dcbb9267466c

Author
Johan Sjöblom <sjoblomj88@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(bgnotify): add icon parameter (#12055)

Diff

 1diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh
 2index 493a20815c787ad6bcd94466863912990a8de249..a4a7b621be35bb45929f5c2acca8e7f03c5a012d 100644
 3--- a/plugins/bgnotify/bgnotify.plugin.zsh
 4+++ b/plugins/bgnotify/bgnotify.plugin.zsh
 5@@ -52,10 +52,10 @@ function bgnotify_formatted {
 6   (( $3 < 60 )) || elapsed="$((( $3 % 3600) / 60 ))m $elapsed"
 7   (( $3 < 3600 )) || elapsed="$(( $3 / 3600 ))h $elapsed"
 8 
 9-  if [[ $1 -eq 0 ]]; then
10-    bgnotify "#win (took $elapsed)" "$2"
11+  if [[ $exit_status -eq 0 ]]; then
12+    bgnotify "#win (took $elapsed)" "$cmd"
13   else
14-    bgnotify "#fail (took $elapsed)" "$2"
15+    bgnotify "#fail (took $elapsed)" "$cmd"
16   fi
17 }
18 
19@@ -66,7 +66,7 @@ function bgnotify_appid {
20   elif [[ -n $WAYLAND_DISPLAY ]] && (( ${+commands[swaymsg]} )) && (( ${+commands[jq]} )); then # wayland+sway
21     # output is "app_id, container id" (Alacritty, 1694)
22     swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | {app_id, id} | join(", ")'
23-  elif [[ -n $DISPLAY ]] && (( ${+commands[xprop]} )); then
24+  elif [[ -z $WAYLAND_DISPLAY ]] && [[ -n $DISPLAY ]] && (( ${+commands[xprop]} )); then
25     xprop -root _NET_ACTIVE_WINDOW 2>/dev/null | cut -d' ' -f5
26   else
27     echo $EPOCHSECONDS
28@@ -76,6 +76,7 @@ function bgnotify_appid {
29 function bgnotify {
30   local title="$1"
31   local message="$2"
32+  local icon="$3"
33   if (( ${+commands[terminal-notifier]} )); then # macOS
34     local term_id="${bgnotify_termid%%,*}" # remove window id
35     if [[ -z "$term_id" ]]; then
36@@ -85,23 +86,15 @@ function bgnotify {
37       esac
38     fi
39 
40-    if [[ -z "$term_id" ]]; then
41-      terminal-notifier -message "$message" -title "$title" &>/dev/null
42-    else
43-      terminal-notifier -message "$message" -title "$title" -activate "$term_id" -sender "$term_id" &>/dev/null
44-    fi
45+    terminal-notifier -message "$message" -title "$title" ${=icon:+-appIcon "$icon"} ${=term_id:+-activate "$term_id" -sender "$term_id"} &>/dev/null
46   elif (( ${+commands[growlnotify]} )); then # macOS growl
47     growlnotify -m "$title" "$message"
48   elif (( ${+commands[notify-send]} )); then
49-    if [[ -n $ALACRITTY_WINDOW_ID ]]; then
50-        notify-send -i Alacritty "$title" "$message"
51-    else
52-        notify-send "$title" "$message"
53-    fi
54+    notify-send "$title" "$message" ${=icon:+--icon "$icon"}
55   elif (( ${+commands[kdialog]} )); then # KDE
56     kdialog --title "$title" --passivepopup  "$message" 5
57   elif (( ${+commands[notifu]} )); then # cygwin
58-    notifu /m "$message" /p "$title"
59+    notifu /m "$message" /p "$title" ${=icon:+/i "$icon"}
60   fi
61 }
62