I recently found myself task-switching quite a bit, and losing track of longer running programs in the process. I went looking for a low effort way to get Terminal to display a notification when a program exited while terminal (or the running shell session) was in the background. I quickly found a solution in two parts:
terminal-notifier
terminal-notifier is a Mac App that provides a simple CLI to create notifications in notification center. Pipe text in, get a notification out. Easy.
Now for the shell integration:
zsh-notify
zsh-notify is a plugin for zsh that supports terminal-notifier, as well as growl (for ye olden MacOS versions ;)).
Configuration
There’s really only one option to configure, and that’s the notification timeout. You set this as an environment variable:
export NOTIFY_COMMAND_COMPLETE_TIMEOUT=5
This will create a notification for any task that takes longer than 5 seconds. The default is 30, which is way too long for my twitchy, app-switching fingers.
Cool, but I don’t use zsh…
Well, you should give it a try!
I don’t use bash any longer, but with terminal-notifier it’s super easy to fire them off ad hoc:
./run-a-long-program && terminal-notifier -message "Finished run-a-long-program"
And voila!
But seriously, you should try zsh.