I have something like this in my bashrc:
preexec ()
{
# shellcheck disable=2034
_CMD_START="$(date +%s)"
}
trap 'preexec; trap - DEBUG' DEBUG
PROMPT_COMMAND="_CMD_STOP=\$(date +%s)
let _CMD_ELAPSED=_CMD_STOP-_CMD_START
if [ \$_CMD_ELAPSED -gt 5 ]; then
_TIME_STR=\" (\${_CMD_ELAPSED}s)\"
else
_TIME_STR=''
fi; "
PS1="\n\u@\h \w\$_TIME_STR\n\\$ "
PROMPT_COMMAND+="trap 'preexec; trap - DEBUG' DEBUG"
Whenever a command takes more than 5 s it tells me exactly how long at the next prompt.I didn't know about `$SECONDS` so I'm going to change it to use that.