0

I want to get informed when long running command finished.

For example I need to get informed when git pull finish. Right now I can use git pull; tput bel and terminal app will inform me that console require my attention.

Is it possible to execute tput bel for every command I enter in shell that was run more than 10 seconds?

I'm using tput bel as it works from local and remote ssh sessions.

Eugene Nagorny
  • 1,626
  • 3
  • 18
  • 32
  • 2
    See [Automatically timing every executed command and show in Bash prompt?](http://stackoverflow.com/questions/1176386/automatically-timing-every-executed-command-and-show-in-bash-prompt) and expand to fit your needs. – RedX Jan 14 '14 at 11:41

1 Answers1

1

Thanks @RedX I found what I need. I ended up with adding this to my .bash_profile:

function timer_start {
  timer=${timer:-$SECONDS}
}

function timer_stop {
  timer_show=$(($SECONDS - $timer))
  if [[ $timer_show -ge '10' ]]; then
    tput bel
  fi
  unset timer
}

trap 'timer_start' DEBUG
PROMPT_COMMAND=timer_stop

This will execute tput bell and my terminal will bounce if it out of focus, every time my command was executed longer than 10 seconds.

Additionally you can add $timer_show to your PS1 to show duration in seconds of every command.

Eugene Nagorny
  • 1,626
  • 3
  • 18
  • 32