From 7aa78e94d13be17a21fae2afd70802b0f1f38596 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sun, 7 Apr 2024 23:23:18 +0100 Subject: [PATCH] Notify via OSC 9 after long running command completes --- utilities/utilities.plugin.zsh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utilities/utilities.plugin.zsh b/utilities/utilities.plugin.zsh index 357b65d..d0d5d0a 100644 --- a/utilities/utilities.plugin.zsh +++ b/utilities/utilities.plugin.zsh @@ -43,6 +43,24 @@ notify() { tmux-dcs-passthrough '\x1b]9;'"$*"'\x7' } +# Send a desktop notification when long running commands complete. +notify_command_threshold=60 +notify-preexec() { + notify_command_start=`date +%s` + notify_command=$1 +} +notify-precmd() { + if ! [[ -z $notify_command_start ]]; then + local notify_command_end=`date +%s` + local notify_command_time=$(($notify_command_end - $notify_command_start)) + if [[ $notify_command_time -gt $notify_command_threshold ]]; then + notify "completed: $notify_command" + fi + fi +} +add-zsh-hook preexec notify-preexec +add-zsh-hook precmd notify-precmd + # Detect the type and extract an archive file. extract() { if [ -f $1 ]; then