README.md
1# watcher command
2
3# Installation
4
5```shell
6go get -u github.com/radovskyb/watcher/...
7```
8
9# Usage
10
11```
12Usage of watcher:
13 -cmd string
14 command to run when an event occurs
15 -dotfiles
16 watch dot files (default true)
17 -ignore string
18 comma separated list of paths to ignore
19 -interval string
20 watcher poll interval (default "100ms")
21 -keepalive
22 keep alive when a cmd returns code != 0
23 -list
24 list watched files on start
25 -pipe
26 pipe event's info to command's stdin
27 -recursive
28 watch folders recursively (default true)
29 -startcmd
30 run the command when watcher starts
31```
32
33All of the flags are optional and watcher can be simply called by itself:
34```shell
35watcher
36```
37(watches the current directory recursively for changes and notifies for any events that occur.)
38
39A more elaborate example using the `watcher` command:
40```shell
41watcher -dotfiles=false -recursive=false -cmd="./myscript" main.go ../
42```
43In this example, `watcher` will ignore dot files and folders and won't watch any of the specified folders recursively. It will also run the script `./myscript` anytime an event occurs while watching `main.go` or any files or folders in the previous directory (`../`).
44
45Using the `pipe` and `cmd` flags together will send the event's info to the command's stdin when changes are detected.
46
47First create a file called `script.py` with the following contents:
48```python
49import sys
50
51for line in sys.stdin:
52 print (line + " - python")
53```
54
55Next, start watcher with the `pipe` and `cmd` flags enabled:
56```shell
57watcher -cmd="python script.py" -pipe=true
58```
59
60Now when changes are detected, the event's info will be output from the running python script.
61