From the Canyon Edge -- :-Dustin

Monday, July 26, 2010

Dear Bash, please ping me when you're done running $FOO


UPDATE: The "alert" alias has landed in Maverick's /etc/skel/.bashrc ... thanks for your support!!!

How often do you run a command line tool on your desktop that takes a really long time? Maybe something like make, debuild, rsync, or wget?

You probably kick off the long running job, and then alt-tab over to something more captivating than watching gcc fill your scroll back buffer -- maybe your web browser or news reader.

You occasionally pop back over to your shell to check on your job. Maybe it's still running. But maybe it finished a while ago. Dang.

No need to beat yourself up over wasted cycles. You can tell your shell to ping you when it's done. Just add this alias to your ~/.bashrc.


alias alert='notify-send --urgency=low -i "$([ $? = 0 ] \
&& echo terminal || echo error)" "$(history|tail -n1| \
sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

Install the notify-send utility, and source your new ~/.bashrc:

sudo apt-get install libnotify-bin
. ~/.bashrc

Now, run a long running job, and append "; alert" to the end of the command, like this:

sleep 20; alert

After running the target command, the alert alias will render a notify-osd pop-up on your desktop, telling you the command you just ran, and its exit code.


Nifty, huh?

:-Dustin