Don't notify when select commands exit

This commit is contained in:
Kenneth Benzie 2024-04-12 22:17:27 +01:00
parent 6678fe0aaf
commit a9fb5104ac
2 changed files with 31 additions and 3 deletions

View File

@ -38,17 +38,33 @@ tmux-dcs-passthrough() {
fi fi
} }
# OSC 9 - Post a notification - supported by iTerm2, kitty, maybe others? # OSC 9 - Post a notification - supported by iTerm2, kitty, WezTerm, others?
notify() { notify() {
tmux-dcs-passthrough '\x1b]9;'"$*"'\x7' tmux-dcs-passthrough '\x1b]9;'"$*"'\x7'
} }
# Send a desktop notification when long running commands complete. # 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() { notify-preexec() {
if notify-ignore $1; then
return
fi
notify_command_start=`date +%s` notify_command_start=`date +%s`
notify_command=$1 notify_command=$1
} }
add-zsh-hook preexec notify-preexec
notify-precmd() { notify-precmd() {
if ! [[ -z $notify_command_start ]]; then if ! [[ -z $notify_command_start ]]; then
local notify_command_end=`date +%s` local notify_command_end=`date +%s`
@ -56,9 +72,10 @@ notify-precmd() {
if [[ $notify_command_time -gt $notify_command_threshold ]]; then if [[ $notify_command_time -gt $notify_command_threshold ]]; then
notify "completed: $notify_command" notify "completed: $notify_command"
fi fi
unset notify_command
unset notify_command_start
fi fi
} }
add-zsh-hook preexec notify-preexec
add-zsh-hook precmd notify-precmd add-zsh-hook precmd notify-precmd
# Detect the type and extract an archive file. # Detect the type and extract an archive file.

11
zshrc
View File

@ -231,3 +231,14 @@ esac
command -v wol > /dev/null && \ command -v wol > /dev/null && \
alias wakeonlan='wol' 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