From e7253df7ad536e2a1b7198db6d04a4652f64e585 Mon Sep 17 00:00:00 2001 From: mikob Date: Tue, 27 Oct 2020 16:29:55 -0600 Subject: [PATCH] check if window is not the same as the one where the command started executing on expiration to show notifications in a smarter way --- README.rst | 9 +++++++++ auto-notify.plugin.zsh | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e5dad79..4f6bc83 100644 --- a/README.rst +++ b/README.rst @@ -154,6 +154,15 @@ then all the values in ``AUTO_NOTIFY_IGNORE`` are not used. export AUTO_NOTIFY_WHITELIST=("apt-get" "docker") +**Ignoring Window Check** + +By default the notification only shows if the active window is not the same as the the one that the command was run +in when the command finishes. If you wish to skip window checking, set ``AUTO_NOTIFY_IGNORE_WINDOW_CHECK``. + +:: + + export AUTO_NOTIFY_IGNORE_WINDOW_CHECK=true + Temporarily Disabling Notifications ----------------------------------- diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 5ed5c95..9e4713a 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -53,6 +53,14 @@ function _auto_notify_message() { fi } +function _auto_notify_active_window_id () { + if [[ -n $DISPLAY ]] ; then + xprop -root _NET_ACTIVE_WINDOW | awk '{print $5}' + return + fi + echo nowindowid +} + function _is_auto_notify_ignored() { local command="$1" # split the command if its been piped one or more times @@ -101,8 +109,12 @@ function _auto_notify_send() { if [[ "$(_is_auto_notify_ignored "$AUTO_COMMAND_FULL")" == "no" ]]; then local current="$(date +"%s")" let "elapsed = current - AUTO_COMMAND_START" + local current_window="$(_auto_notify_active_window_id)" - if [[ $elapsed -gt $AUTO_NOTIFY_THRESHOLD ]]; then + if [[ $current_window != $AUTO_NOTIFY_ACTIVE_WINDOW_ID ]] || + [[ ! -z "$AUTO_NOTIFY_IGNORE_WINDOW_CHECK" ]] || + [[ $current_window == "nowindowid" ]] && + [[ $elapsed -gt $AUTO_NOTIFY_THRESHOLD ]]; then _auto_notify_message "$AUTO_COMMAND" "$elapsed" "$exit_code" fi fi @@ -119,6 +131,7 @@ function _auto_notify_track() { AUTO_COMMAND="${1:-$2}" AUTO_COMMAND_FULL="$3" AUTO_COMMAND_START="$(date +"%s")" + AUTO_NOTIFY_ACTIVE_WINDOW_ID="$(_auto_notify_active_window_id)" } function _auto_notify_reset_tracking() { @@ -128,6 +141,8 @@ function _auto_notify_reset_tracking() { unset AUTO_COMMAND_FULL # Command that the user has executed unset AUTO_COMMAND + # window id of where the command was executed + unset AUTO_NOTIFY_ACTIVE_WINDOW_ID } function disable_auto_notify() {