How to automatically watch for file changes and perform a custom action inside shell? For example, I'd like to automatically run YUI Compressor whenever I edit a JavaScript source file to output a compressed version.

Ideally the process does not run in the background but in a dedicated shell, so I can easily terminate the process at the end of the day.

What would be the cleanest and most flexible way to watch specific files and/or directories for file changes and perform a custom action inside a shell?
The $25 Codekit does watch folders and files for changes and does compress/minify/combine JavaScript and CSS files. 

I know this is only a partial answer for your question, as it is not a generic watcher, but it does fit your example:


  whenever I edit a JavaScript source file to output a compressed
  version