watch

Watch your files and run commands on changes from a crystal script

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      watch:
        github: danreeves/watch
  2. Run shards install

Usage

Create a crystal file to be your task manager, something like watch.cr

require "watch"

Watch.watch "./src/**/*.cr", "crystal build src/main.cr"
Watch.watch "./*", "echo \"wow a file changed\"", opts: [:verbose, :log_changes]
Watch.run

Now you can run it with crystal run watch.cr and rebuild your main application whenever a file changes. Useful for webservers like Kemal!

Every Watch.watch is run in it's own Fiber so you can have multiple tasks doing different things looking at different files.

Watch.watch(glob: String, command: String, opts: [], interval: Int32)

watch takes a glob of files to watch and a command to run. Configuration is provided by opts and includes:

Watch.run

Required to be called at the end of your watch script to prevent the process for finishing.

Contributing

  1. Fork it (https://github.com/danreeves/watch/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors