Never miss completion of a long-running command again!

·Clayton Craft

This is a really short, simple thing I use to alert me when a long-running shell command/script, like building (some) containers or compiling the kernel, is done. It effectively allows me to switch context in the meantime and pick up where I left off when the long-running dependency is finished.

There are two versions of this, one triggers the shell bell after the command/script has completed, and the other uses notify-send to trigger a desktop notification. I prefer the shell bell approach most of the time, since it works nicely with my tmux setup, highlighting the window where it was triggered. It also works if there's no graphical notification daemon running.

alert () {
        "$@"; tput bel

And the notify-send version:

alert () {
        "$@"; notify-send "ding!" "$*"

These can be used by adding the function to you shell's rc script (e.g. ~/.zshrc for zsh or ~/.bashrc for bash). It may need to be adjusted for shells that use a different syntax for defining user functions.

To use it, simply run the function and pass the script+args to it, for example: $ alert make -j1 foo or whatever.

(2022/07) Thanks to Eric Engestrom for pointing out a mistake with the notify-send command! The $@ should have been a $* to collapse the command+args into a single string for passing to notify-send (fixed in the example above.)