The modern Linux desktop is a fertile landscape for developers. Especially with a good package manager, such as Debian's apt system. Add to that multiple desktops, and awesome tools like screen and tmux, and complicated knowledge work can be handled with relative ease.
Of course, this presents its own problem. When you're "multi-tasking" (in quotes because human's really can't), you often find yourself waiting for something to complete, such as reloading a test database, downloading a backup, or running a test suite. Of course you immediately switch to another desktop or session to pick up another task. Or go check your e-mail. Whatever.
As a result, you idly flip among your work surfaces to find that some task finished hours ago. Or worse -- it failed hours ago and now you have to re-launch it. If only you'd been alerted at the time!
A great tool is the notify-send application that comes with Ubuntu:
do_my_task; notify-send "the thing is done"
This causes a "growl-like" window to pop up -- the semi-transparent black window that shows up on the top-right of your screen to let you know someone sent you an IM, or Dropbox updated some files, or whatever.
One problem I've found with this is that I'm usually in a full-screen terminal, and that little black box often goes unnoticed. So I built a little shell script which dumps the output of my command into that box so it becomes a big black box, much easier to notice. But the main advantage is that the output of the command is shown in the box, so I can know right away if I want to drop what I'm doing to go handle it:
#!/usr/bin/env bash temp=$(mktemp --suffix TELLME) cat /dev/stdin > $temp; cat $temp | xargs -0 notify-send -i /some/cool/picture.jpg -t 15000 "Something Finished: $temp" && cat $temp
Here's the breakdown:
- By creating a tempfile, I can view the entire output later if it's too long and scrolls off the page.
- Using xargs -0 lets notify-send take the entire output, whitespace and all, and display it.
- Optionally adding an image with the -i flag makes it stand out more.
- The final cat means that the output will be on the screen when you go back to that terminal. This is because, to call tellme in the first place, you piped the output to tellme and it was never shown originally.
- Increasing the timeout to 15 seconds from the default five makes it more likely that you'll notice it.
To call tellme:
my_command |& tellme
This will cause the program to run and then, whether it fails or succeeds, the output that would have gone to the terminal will pop up on your screen.
Using |& instead of just | will send both standard output and standand error to tellme, intsead of just the standard output.
To make the script executable, put it in a location on your $PATH and make it executable. I always add a bin folder in my home directory to my $PATH.
Assuming you've put tellme in your home/bin folder:
cd ~/bin chmod +x tellme
And that's it. Enjoy!