Notify After Command

Sequential commands

On sh like shells you can use && to execute a second command if first finish with status 0, and || to execute a second command in case of a non-zero exit status, a combination of both.

Examples:

docker build . && echo "Success" || echo "Fail"

Using ; instead, it will execute a second command regardless.

Linux notification system

Modern linux comes with a utility called notify-send to send desktop notifications through the command line, as simple as:

notify-send summary "Notification content"

Useful trick to run long consuming commands and notify on finish

Create a file on $PATH with a simple name, like ntf:

notify-send -u normal -t 2000 -a Appname "Summary" "$1" > /dev/null 2>&1

And whenever you need to be notified after a command use:

docker build . ; ntf "Finish"