EDIT

TL;DR: create autocompletion shortcut in .inputrc and function in .bashrc . Run command as usual, type in, but instead of ENTER , press the shortcut that you specified in .inputrc

The person who placed bounty on this question said:

"All of the existing answers require typing an additional command after the command. I want an answer that does this automatically."

While researching the solutions to this problem I've stumbled upon this question from stackexchange, which allows binding Ctrl J to a sequence of commands: Ctrl a (move to beginning of line), place "mesure" string in front of the command you entered, Ctrl m (execute)

Thus you get functionality of auto-completion and separate ENTER command for measuring time, while perserving original purpose of the second function i posted bellow.

As of now, here are the contents of my ~/.inputrc file:

"\C-j": "\C-a measure \C-m"

And here are the contents of .bashrc (note , I haven't been using bash in forever - I use mksh as my shell , hence that's what you see in the original post. Functionality is still the same)

PS1=' serg@ubuntu [$(pwd)] ================================ $ ' function measure () { /usr/bin/time --output="/home/xieerqi/.timefile" -f "%e" $@ if [ $( cat ~/.timefile| cut -d'.' -f1 ) -gt 15 ]; then notify-send "Hi , $@ is done !" fi }

Original Post

Here's my idea - use a function in .bashrc . Basic principle - use /usr/bin/time to measure the time it takes for command to complete, and if it is over 15 seconds, send notification.

function measure () { if [ $( /usr/bin/time -f "%e" $@ 2>&1 >/dev/null ) -gt 15 ]; then notify-send "Hi , $@ is done !" fi }

Here I am redirecting output to /dev/null but to view output, redirecting to file can also be done.

A much better approach, IMHO, is to send output of time to some file in your home folder (just so you don't pollute your system with timefiles, and always know where to look). Here's that second version

function measure () { /usr/bin/time --output=~/.timefile -f "%e" $@ if [ $( cat ~/.timefile | cut -d'.' -f1 ) -gt 15 ]; then notify-send "Hi , $@ is done !" fi }

And here's the screenshots of first and second version, in that order

First version, no output

Second version, with output