2011-05-09

A function to automate `say`

If you’ve seen @twe4ked’s recent post on using say to announce when long command line tasks complete, you might not relish the thought of typing all the announcement text at the end of each line.

So, here - @jasoncodes and I made you something:

function saywhen {
  if eval "$@"
  then
    say "$1 $2 done."
    return 0
  else
    say "$1 $2 error."
    return 1
  fi
}

$ saywhen bundle install

saywhen is a bash function that runs your command and pipes the first word of your command to say. A bundle says ‘bundle done.’, a long running cucumber task says “rake cucumber done.” and… well, you get the point.

Bonus points: Alias saywhen to sw for even less typing and more “omg wtf is that that’s awesome!” from onlookers.

UPDATE: Added an eval before the $@ so that aliases work. Thanks for the heads up @parndt and to @jasoncodes for the fix.

Tags: say unix command line tips 22 notes View comments

  1. lucas-todayilearned posted this
Blog comments powered by Disqus