Comment

Comment by wolfgang42

The article mentions not wanting to put a bell in their terminal prompt because it would cause too many notifications, but I found it difficult to remember to put `;tput bel` on every command that would be slow, so I compromised by configuring my shell to notify only on commands that took longer than 10 seconds. I also use a popup instead of a straight bell so I'll see a reminder of what it was that was happening (this is for MacOS, on Linux it would use `notify-send` instead):

    function preexec() {
      lrn_timer=${timer:-$SECONDS}
      lrn_command="$1"
    }
    lrn_timer=0
    function precmd() {
      [[ -v lrn_timer ]] || return # preexec() doesn't set timer if no command run (e.g. from ^C before running)
      timer_show=$(($SECONDS - $lrn_timer))
      unset lrn_timer
      # 10 is the notification threshold in seconds
      if (( ${timer_show} > 10 )); then
        terminal-notifier -sound default -message "Exit $? in ${timer_show}s: $lrn_command"
      fi
    }
(Based on https://gist.github.com/petethepig/2d29e8b7e2ebc808bfe760b63...)
parent wolfgang42 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton