Bash function to notify when a command finishes

I've just written a short bash function which notifies you when a command has finished running, using libnotify and notify-send (on ubuntu, make sure the package 'libnotify-bin' is installed).

Just copy the text below into one of your bash startup files. (E.g. ~/.bashrc, or /etc/bash.bashrc)

function notify() { 
  # notify <command> <args> - sends a popup notification when a command finishes
  cmd=$1; shift
  $cmd $@ 
  err=$?
  [ $err -eq 0 ] && \
  notify-send "$cmd $*" "Finished: OK" || \
  notify-send "$cmd $*" "Finished: Error" 
}

To use it, run the command you are invoking preceded by 'notify'. E.g. if you are building a project using make, you would type 'notify make'.

When it's finished, you get a notification.

 
blog/bash_function_to_notify_when_a_command_finishes.txt · Last modified: 2012/02/13 22:04 by andy
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki