Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell. Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done. Change variable names to match lib/command-duration Remove `preexec_return_notification()` in favor of `lib/command-duration`'s `_command_duration_pre_exec()`. This should now use the same preexec hook and variables as the theme library `command_duration`. tests: handle nanoseconds
17 lines
559 B
Bash
17 lines
559 B
Bash
# shellcheck shell=bash
|
|
cite about-plugin
|
|
about-plugin 'Alert (BEL) when process ends after a threshold of seconds'
|
|
|
|
function precmd_return_notification() {
|
|
local command_start="${COMMAND_DURATION_START_SECONDS:=0}"
|
|
local current_time="${EPOCHREALTIME:-$SECONDS}"
|
|
local -i command_duration="$((${current_time%.*} - ${command_start%.*}))"
|
|
if [[ "${command_duration}" -gt "${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5}" ]]; then
|
|
printf '\a'
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
safe_append_prompt_command 'precmd_return_notification'
|
|
safe_append_preexec '_command_duration_pre_exec'
|