From 9004c177bac951f46ab1ec5b74a8bcfb8e3c686b Mon Sep 17 00:00:00 2001 From: Gautam krishna R Date: Fri, 22 Dec 2023 14:27:23 +0530 Subject: fix(bgnotify): make it work with `set -e` (#12111) Co-authored-by: ipChrisLee --- plugins/bgnotify/bgnotify.plugin.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/bgnotify/bgnotify.plugin.zsh') diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh index 3c0766191..c28a29e19 100644 --- a/plugins/bgnotify/bgnotify.plugin.zsh +++ b/plugins/bgnotify/bgnotify.plugin.zsh @@ -21,11 +21,11 @@ function bgnotify_end { local elapsed=$(( EPOCHSECONDS - bgnotify_timestamp )) # check time elapsed - [[ $bgnotify_timestamp -gt 0 ]] || return - [[ $elapsed -ge $bgnotify_threshold ]] || return + [[ $bgnotify_timestamp -gt 0 ]] || return 0 + [[ $elapsed -ge $bgnotify_threshold ]] || return 0 # check if Terminal app is not active - [[ $(bgnotify_appid) != "$bgnotify_termid" ]] || return + [[ $(bgnotify_appid) != "$bgnotify_termid" ]] || return 0 [[ $bgnotify_bell = true ]] && printf '\a' # beep sound bgnotify_formatted "$exit_status" "$bgnotify_lastcmd" "$elapsed" -- cgit v1.2.3-70-g09d2 From 64d881b479cec5e62384176773f1b4d0a057ba47 Mon Sep 17 00:00:00 2001 From: Brian Hartvigsen Date: Wed, 27 Dec 2023 02:57:53 -0700 Subject: fix(bgnotify): don't require accessibility perms in macos (#11433) --- plugins/bgnotify/bgnotify.plugin.zsh | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'plugins/bgnotify/bgnotify.plugin.zsh') diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh index c28a29e19..0e3f2c640 100644 --- a/plugins/bgnotify/bgnotify.plugin.zsh +++ b/plugins/bgnotify/bgnotify.plugin.zsh @@ -27,7 +27,6 @@ function bgnotify_end { # check if Terminal app is not active [[ $(bgnotify_appid) != "$bgnotify_termid" ]] || return 0 - [[ $bgnotify_bell = true ]] && printf '\a' # beep sound bgnotify_formatted "$exit_status" "$bgnotify_lastcmd" "$elapsed" } always { bgnotify_timestamp=0 @@ -52,6 +51,7 @@ function bgnotify_formatted { (( $3 < 60 )) || elapsed="$((( $3 % 3600) / 60 ))m $elapsed" (( $3 < 3600 )) || elapsed="$(( $3 / 3600 ))h $elapsed" + [[ $bgnotify_bell = true ]] && printf '\a' # beep sound if [[ $exit_status -eq 0 ]]; then bgnotify "#win (took $elapsed)" "$cmd" else @@ -61,10 +61,9 @@ function bgnotify_formatted { function bgnotify_appid { if (( ${+commands[osascript]} )); then - # output is "app ID, window ID" (com.googlecode.iterm2, 116) - osascript -e 'tell application (path to frontmost application as text) to get the {id, id of front window}' 2>/dev/null + osascript -e "tell application id \"$(bgnotify_programid)\" to get the {id, frontmost, id of front window, visible of front window}" 2>/dev/null elif [[ -n $WAYLAND_DISPLAY ]] && (( ${+commands[swaymsg]} )); then # wayland+sway - local app_id=$(find_sway_appid) + local app_id=$(bgnotify_find_sway_appid) [[ -n "$app_id" ]] && echo "$app_id" || echo $EPOCHSECONDS elif [[ -z $WAYLAND_DISPLAY ]] && [[ -n $DISPLAY ]] && (( ${+commands[xprop]} )); then xprop -root _NET_ACTIVE_WINDOW 2>/dev/null | cut -d' ' -f5 @@ -74,7 +73,7 @@ function bgnotify_appid { } -function find_sway_appid { +function bgnotify_find_sway_appid { # output is "app_id,container_id", for example "Alacritty,1694" # see example swaymsg output: https://github.com/ohmyzsh/ohmyzsh/files/13463939/output.json if (( ${+commands[jq]} )); then @@ -105,15 +104,11 @@ function find_sway_appid { fi } -function find_term_id { - local term_id="${bgnotify_termid%%,*}" # remove window id - if [[ -z "$term_id" ]]; then - case "$TERM_PROGRAM" in - iTerm.app) term_id='com.googlecode.iterm2' ;; - Apple_Terminal) term_id='com.apple.terminal' ;; - esac - fi - echo "$term_id" +function bgnotify_programid { + case "$TERM_PROGRAM" in + iTerm.app) echo 'com.googlecode.iterm2' ;; + Apple_Terminal) echo 'com.apple.terminal' ;; + esac } function bgnotify { @@ -121,7 +116,7 @@ function bgnotify { local message="$2" local icon="$3" if (( ${+commands[terminal-notifier]} )); then # macOS - local term_id=$(find_term_id) + local term_id=$(bgnotify_programid) terminal-notifier -message "$message" -title "$title" ${=icon:+-appIcon "$icon"} ${=term_id:+-activate "$term_id" -sender "$term_id"} &>/dev/null elif (( ${+commands[growlnotify]} )); then # macOS growl growlnotify -m "$title" "$message" -- cgit v1.2.3-70-g09d2 From e53edd712f28170a0843ce1d2a61efe335484ad4 Mon Sep 17 00:00:00 2001 From: David LJ Date: Tue, 4 Jun 2024 15:55:08 +0200 Subject: fix(bgnotify): use terminal-notifier args properly (#12467) --- plugins/bgnotify/bgnotify.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/bgnotify/bgnotify.plugin.zsh') diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh index 0e3f2c640..7de6f9a91 100644 --- a/plugins/bgnotify/bgnotify.plugin.zsh +++ b/plugins/bgnotify/bgnotify.plugin.zsh @@ -117,7 +117,7 @@ function bgnotify { local icon="$3" if (( ${+commands[terminal-notifier]} )); then # macOS local term_id=$(bgnotify_programid) - terminal-notifier -message "$message" -title "$title" ${=icon:+-appIcon "$icon"} ${=term_id:+-activate "$term_id" -sender "$term_id"} &>/dev/null + terminal-notifier -message "$message" -title "$title" ${=icon:+-appIcon "$icon"} ${=term_id:+-activate "$term_id"} &>/dev/null elif (( ${+commands[growlnotify]} )); then # macOS growl growlnotify -m "$title" "$message" elif (( ${+commands[notify-send]} )); then -- cgit v1.2.3-70-g09d2 From ac325a7caba6630538c39e1c0ffa192d866cdcff Mon Sep 17 00:00:00 2001 From: PukNgae Cryolitia Date: Mon, 16 Sep 2024 05:20:59 +0800 Subject: feat(bgnotify): add config to pass extra args (#12679) --- plugins/bgnotify/README.md | 1 + plugins/bgnotify/bgnotify.plugin.zsh | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'plugins/bgnotify/bgnotify.plugin.zsh') diff --git a/plugins/bgnotify/README.md b/plugins/bgnotify/README.md index 33d529f15..1389def86 100644 --- a/plugins/bgnotify/README.md +++ b/plugins/bgnotify/README.md @@ -38,6 +38,7 @@ One can configure a few things: - `bgnotify_bell` enabled or disables the terminal bell (default true) - `bgnotify_threshold` sets the notification threshold time (default 6 seconds) - `function bgnotify_formatted` lets you change the notification. You can for instance customize the message and pass in an icon. +- `bgnotify_extraargs` appends extra args to notifier (e.g. `-e` for notify-send to create a transient notification) Use these by adding a function definition before the your call to source. Example: diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh index 7de6f9a91..f6ffb6ed5 100644 --- a/plugins/bgnotify/bgnotify.plugin.zsh +++ b/plugins/bgnotify/bgnotify.plugin.zsh @@ -117,15 +117,15 @@ function bgnotify { local icon="$3" if (( ${+commands[terminal-notifier]} )); then # macOS local term_id=$(bgnotify_programid) - terminal-notifier -message "$message" -title "$title" ${=icon:+-appIcon "$icon"} ${=term_id:+-activate "$term_id"} &>/dev/null + terminal-notifier -message "$message" -title "$title" ${=icon:+-appIcon "$icon"} ${=term_id:+-activate "$term_id"} ${=bgnotify_extraargs:-} &>/dev/null elif (( ${+commands[growlnotify]} )); then # macOS growl - growlnotify -m "$title" "$message" + growlnotify -m "$title" "$message" ${=bgnotify_extraargs:-} elif (( ${+commands[notify-send]} )); then - notify-send "$title" "$message" ${=icon:+--icon "$icon"} + notify-send "$title" "$message" ${=icon:+--icon "$icon"} ${=bgnotify_extraargs:-} elif (( ${+commands[kdialog]} )); then # KDE - kdialog --title "$title" --passivepopup "$message" 5 + kdialog --title "$title" --passivepopup "$message" 5 ${=bgnotify_extraargs:-} elif (( ${+commands[notifu]} )); then # cygwin - notifu /m "$message" /p "$title" ${=icon:+/i "$icon"} + notifu /m "$message" /p "$title" ${=icon:+/i "$icon"} ${=bgnotify_extraargs:-} fi } -- cgit v1.2.3-70-g09d2 From 899af6328b395f1db2e74d09880a1af435a188ca Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Fri, 21 Mar 2025 12:47:25 +0100 Subject: fix(bgnotify): detect if sway is running and not just installed (#12989) Co-authored-by: Carlo Sala --- plugins/bgnotify/bgnotify.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/bgnotify/bgnotify.plugin.zsh') diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh index f6ffb6ed5..dca8250be 100644 --- a/plugins/bgnotify/bgnotify.plugin.zsh +++ b/plugins/bgnotify/bgnotify.plugin.zsh @@ -62,7 +62,7 @@ function bgnotify_formatted { function bgnotify_appid { if (( ${+commands[osascript]} )); then osascript -e "tell application id \"$(bgnotify_programid)\" to get the {id, frontmost, id of front window, visible of front window}" 2>/dev/null - elif [[ -n $WAYLAND_DISPLAY ]] && (( ${+commands[swaymsg]} )); then # wayland+sway + elif [[ -n $WAYLAND_DISPLAY ]] && ([[ -n $SWAYSOCK ]] || [[ -n $I3SOCK ]]) && (( ${+commands[swaymsg]} )); then # wayland+sway local app_id=$(bgnotify_find_sway_appid) [[ -n "$app_id" ]] && echo "$app_id" || echo $EPOCHSECONDS elif [[ -z $WAYLAND_DISPLAY ]] && [[ -n $DISPLAY ]] && (( ${+commands[xprop]} )); then -- cgit v1.2.3-70-g09d2 From 2b2d6d746ca3ed6dfac26be331e49fa80a1191ab Mon Sep 17 00:00:00 2001 From: Denys Dovhan Date: Fri, 19 Sep 2025 16:39:50 +0300 Subject: fix(bgnotify): use lsappinfo, add support for ghostty (#13314) --- plugins/bgnotify/bgnotify.plugin.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'plugins/bgnotify/bgnotify.plugin.zsh') diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh index dca8250be..4c1613eed 100644 --- a/plugins/bgnotify/bgnotify.plugin.zsh +++ b/plugins/bgnotify/bgnotify.plugin.zsh @@ -60,8 +60,10 @@ function bgnotify_formatted { } function bgnotify_appid { - if (( ${+commands[osascript]} )); then - osascript -e "tell application id \"$(bgnotify_programid)\" to get the {id, frontmost, id of front window, visible of front window}" 2>/dev/null + if (( ${+commands[lsappinfo]} )); then + lsappinfo info -only bundleid "$(lsappinfo front)" | awk -F= '{print $2}' | tr -d '"' 2>/dev/null + elif (( ${+commands[osascript]} )); then + osascript -e "tell application id \"$(bgnotify_programid)\" to get the {id, frontmost, id of front window, visible of front window}" 2>/dev/null elif [[ -n $WAYLAND_DISPLAY ]] && ([[ -n $SWAYSOCK ]] || [[ -n $I3SOCK ]]) && (( ${+commands[swaymsg]} )); then # wayland+sway local app_id=$(bgnotify_find_sway_appid) [[ -n "$app_id" ]] && echo "$app_id" || echo $EPOCHSECONDS @@ -108,6 +110,7 @@ function bgnotify_programid { case "$TERM_PROGRAM" in iTerm.app) echo 'com.googlecode.iterm2' ;; Apple_Terminal) echo 'com.apple.terminal' ;; + ghostty) echo 'com.mitchellh.ghostty' ;; esac } -- cgit v1.2.3-70-g09d2