Diff
1diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh
2index c28a29e19cf3829ed4a5c94d13887053401233c6..0e3f2c640d5723532ed339974de043507a5682d3 100644
3--- a/plugins/bgnotify/bgnotify.plugin.zsh
4+++ b/plugins/bgnotify/bgnotify.plugin.zsh
5@@ -27,7 +27,6 @@ function bgnotify_end {
6 # check if Terminal app is not active
7 [[ $(bgnotify_appid) != "$bgnotify_termid" ]] || return 0
8
9- [[ $bgnotify_bell = true ]] && printf '\a' # beep sound
10 bgnotify_formatted "$exit_status" "$bgnotify_lastcmd" "$elapsed"
11 } always {
12 bgnotify_timestamp=0
13@@ -52,6 +51,7 @@ function bgnotify_formatted {
14 (( $3 < 60 )) || elapsed="$((( $3 % 3600) / 60 ))m $elapsed"
15 (( $3 < 3600 )) || elapsed="$(( $3 / 3600 ))h $elapsed"
16
17+ [[ $bgnotify_bell = true ]] && printf '\a' # beep sound
18 if [[ $exit_status -eq 0 ]]; then
19 bgnotify "#win (took $elapsed)" "$cmd"
20 else
21@@ -61,10 +61,9 @@ function bgnotify_formatted {
22
23 function bgnotify_appid {
24 if (( ${+commands[osascript]} )); then
25- # output is "app ID, window ID" (com.googlecode.iterm2, 116)
26- osascript -e 'tell application (path to frontmost application as text) to get the {id, id of front window}' 2>/dev/null
27+ osascript -e "tell application id \"$(bgnotify_programid)\" to get the {id, frontmost, id of front window, visible of front window}" 2>/dev/null
28 elif [[ -n $WAYLAND_DISPLAY ]] && (( ${+commands[swaymsg]} )); then # wayland+sway
29- local app_id=$(find_sway_appid)
30+ local app_id=$(bgnotify_find_sway_appid)
31 [[ -n "$app_id" ]] && echo "$app_id" || echo $EPOCHSECONDS
32 elif [[ -z $WAYLAND_DISPLAY ]] && [[ -n $DISPLAY ]] && (( ${+commands[xprop]} )); then
33 xprop -root _NET_ACTIVE_WINDOW 2>/dev/null | cut -d' ' -f5
34@@ -74,7 +73,7 @@ function bgnotify_appid {
35 }
36
37
38-function find_sway_appid {
39+function bgnotify_find_sway_appid {
40 # output is "app_id,container_id", for example "Alacritty,1694"
41 # see example swaymsg output: https://github.com/ohmyzsh/ohmyzsh/files/13463939/output.json
42 if (( ${+commands[jq]} )); then
43@@ -105,15 +104,11 @@ function find_sway_appid {
44 fi
45 }
46
47-function find_term_id {
48- local term_id="${bgnotify_termid%%,*}" # remove window id
49- if [[ -z "$term_id" ]]; then
50- case "$TERM_PROGRAM" in
51- iTerm.app) term_id='com.googlecode.iterm2' ;;
52- Apple_Terminal) term_id='com.apple.terminal' ;;
53- esac
54- fi
55- echo "$term_id"
56+function bgnotify_programid {
57+ case "$TERM_PROGRAM" in
58+ iTerm.app) echo 'com.googlecode.iterm2' ;;
59+ Apple_Terminal) echo 'com.apple.terminal' ;;
60+ esac
61 }
62
63 function bgnotify {
64@@ -121,7 +116,7 @@ function bgnotify {
65 local message="$2"
66 local icon="$3"
67 if (( ${+commands[terminal-notifier]} )); then # macOS
68- local term_id=$(find_term_id)
69+ local term_id=$(bgnotify_programid)
70 terminal-notifier -message "$message" -title "$title" ${=icon:+-appIcon "$icon"} ${=term_id:+-activate "$term_id" -sender "$term_id"} &>/dev/null
71 elif (( ${+commands[growlnotify]} )); then # macOS growl
72 growlnotify -m "$title" "$message"