From a9fb5104ac88b022b39049617591a9a0675655c9 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Fri, 12 Apr 2024 22:17:27 +0100 Subject: [PATCH] Don't notify when select commands exit --- utilities/utilities.plugin.zsh | 23 ++++++++++++++++++++--- zshrc | 11 +++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/utilities/utilities.plugin.zsh b/utilities/utilities.plugin.zsh index d0d5d0a..2ad589a 100644 --- a/utilities/utilities.plugin.zsh +++ b/utilities/utilities.plugin.zsh @@ -38,17 +38,33 @@ tmux-dcs-passthrough() { fi } -# OSC 9 - Post a notification - supported by iTerm2, kitty, maybe others? +# OSC 9 - Post a notification - supported by iTerm2, kitty, WezTerm, others? notify() { tmux-dcs-passthrough '\x1b]9;'"$*"'\x7' } # Send a desktop notification when long running commands complete. -notify_command_threshold=60 +notify_command_threshold=5 +notify_ignore_list=( git nvim ssh sudo sudoedit tmux vi vim ) + +notify-ignore() { + for ignore in $notify_ignore_list; do + if [[ "$1" = "$ignore"* ]]; then + return 0 + fi + done + return 1 +} + notify-preexec() { + if notify-ignore $1; then + return + fi notify_command_start=`date +%s` notify_command=$1 } +add-zsh-hook preexec notify-preexec + notify-precmd() { if ! [[ -z $notify_command_start ]]; then local notify_command_end=`date +%s` @@ -56,9 +72,10 @@ notify-precmd() { if [[ $notify_command_time -gt $notify_command_threshold ]]; then notify "completed: $notify_command" fi + unset notify_command + unset notify_command_start fi } -add-zsh-hook preexec notify-preexec add-zsh-hook precmd notify-precmd # Detect the type and extract an archive file. diff --git a/zshrc b/zshrc index 39f0ca5..02f9ddf 100644 --- a/zshrc +++ b/zshrc @@ -231,3 +231,14 @@ esac command -v wol > /dev/null && \ alias wakeonlan='wol' + +# Append any aliases to notify_ignore_list if they contain any ignore commands +# NOTE: Keep this at the end of ~/.zshrc so all aliases are processed +for name in ${(k)aliases}; do + cmd=${${${$(alias $name)#${name}=}#\'}#\"} + for ignore in $notify_ignore_list; do + if [[ "$cmd" = "$ignore"* ]]; then + notify_ignore_list+=( $name ) + fi + done +done