Autorunner is a command line utility that automatically runs a command when a file is saved.
First install node, then:
npm install -g autorunner
At the top of any file, add autorun: COMMAND
, then invoke autorunner
with the filename as an argument. Each time the file is saved, COMMAND
will be run.
For example, say we have a file app.coffee
, and every time the file is saved it should be compiled with coffee -c app.coffee
.
Just add the following line to the top of app.coffee
:
# autorun: coffee -c app.coffee
and watch app.coffee
with autorunner
:
$ autorunner app.coffee
Note that this example could also be accomplished with coffee -wc app.coffee
- autorunner is a more generic solution.
We can generalize the autorun
script by automatically inserting the filename:
# autorun: coffee -c $FILEPATH
Here, $FILEPATH
will be replaced with the full path to app.coffee
before the command is run.
Multiple files can be watched at once by appending them to the argument list, or feeding autorunner
a wildcard.
For example, to autorun the commands on every .coffee
and .rb
script in the current directory, you could use:
$ autorunner *.coffee *.rb
On Mac, add the following to the top of your HTML files:
<!---
autorun: osascript -e 'tell application "Google Chrome" to tell the active tab of its first window to reload'
-->
Then watch them with:
$ autorunner *.html
Add the following to your Ruby files:
# autorun: ruby $FILEPATH
Then watch them with:
$ autorunner *.rb
On Mac, add this to your markdown files:
<!---
autorun: say `wc -w < $FILEPATH` words
-->
Then watch them with:
$ autorunner *.md
Add this to your python script:
# autorun: scp $FILEPATH your_username@remotehost.edu:/some/remote/directory
Then watch them with:
$ autorunner *.py
Pull requests, comments, and criticisms are welcome!