Is there a way to make zsh run a command after REPORTTIME?

If a process takes greater than REPORTTIME, zsh prints the time when it finishes. Is there a way to make it run a custom command in addition to this?(I would like to use notify send to let me know the process finished executing)


I just had the same thought. Did a quick google and found this; I've adapted it a bit. Shove this into your zshrc:

if [[ -x `which notify-send` ]]; then
    notify-preexec-hook() {
        zsh_notifier_cmd="$1"
        zsh_notifier_time="`date +%s`"
    }

    notify-precmd-hook() {
        local time_taken

        if [[ "${zsh_notifier_cmd}" != "" ]]; then
            time_taken=$(( `date +%s` - ${zsh_notifier_time} ))
            if (( $time_taken > $REPORTTIME )); then
                notify-send "task finished" \
                    "'$zsh_notifier_cmd' exited after $time_taken seconds"
            fi
        fi
        zsh_notifier_cmd=
    }
fi

[[ -z $preexec_functions ]] && preexec_functions=()
preexec_functions=($preexec_functions notify-preexec-hook)

[[ -z $precmd_functions ]] && precmd_functions=()
precmd_functions=($precmd_functions notify-precmd-hook)

I'm rather happy with it! :)