Skip to content

loov/watchrun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

14c142d · Oct 1, 2024

History

58 Commits
Oct 1, 2024
Nov 20, 2022
Nov 20, 2022
Sep 25, 2024
Nov 20, 2022
Nov 20, 2022
Dec 22, 2015
Apr 11, 2018
Apr 15, 2023
Apr 14, 2023
Apr 14, 2023
Sep 25, 2024
Sep 25, 2024
Sep 25, 2024
Sep 25, 2024

Repository files navigation

watchrun is a command-line utility to monitor a directory and run a command when any file in that directory changes. It excludes temporary and hidden files that start with . or ~ or end with ~.

To install from source:

go get github.com/loov/watchrun

Example usage:

$ watchrun "go build -o example.exe . == ./example.exe"

Note: directly using watchrun go run main.go, doesn't kill the compiled program automatically, which may cause problems, if you have a server listening.

Then you can test with:

$ echo package main; main(){ println("hello") } > main.go
$ echo package main; main(){ println("world") } > main.go

You can explicitly specify which folder or file to watch with -monitor:

$ watchrun -monitor ../../  "go build -o example.exe . == ./example.exe"
$ watchrun -monitor main.go "go build -o example.exe . == ./example.exe"

You can run multiple commands in succession with == (instead of the usual &&). For example:

$ watchrun go build -i . == myproject

Usage

Usage of watchrun:
  -ignore string
        ignore files/folders that match these globs (default "~*;.*;*~;*.exe")
  -interval duration
        interval to wait between monitoring (default 300ms)
  -monitor string
        files/folders/globs to monitor (default ".")
  -recurse
        when watching a folder should recurse (default true)
  -verbose
        verbose output