My personal favorite for watching files and running context sensitive commands is to use the lovely filewatcher CLI utility written in Ruby.

1gem install filewatcher
2gem install filewatcher-cli

This can then be used with:

1filewatcher '**/*.js' 'node $FILENAME'

However this hasn’t been updated in a while now and fails on newer versions of Ruby. So now I use watchexec.

1cargo install watchexec-cli
2watchexec -w source/f2py 'make html'