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