= Run Command On Changes
:frombash: https://gitlab.com/jzacsh/bin/blob/f38719fdc6795/share/runonchange
:locref: https://gitlab.com/jzacsh/runonchange/blob/
:gomodules: https://blog.golang.org/migrating-to-go-modules
== Overview
Runs an arbitrary command when some filesystem even changes with given filepath(s)
.installation
----
$ go get gitlab.com/jzacsh/runonchange
----
.usage example
----
# Leave this running in a terminal, and go work on your source code elsewhere
$ runonchange 'make clean build && python3 -m http.server' -c -R
----
.for more, see its help output
----
$ runonchange help
Runs COMMAND everytime filesystem events happen under a DIR_TO_WATCH.
Usage: COMMAND [-cdR] [-w WAIT_DURATION] [-i|-r FILE_PATTERN] [DIR_TO_WATCH, ...]
Description:
This program watches filesystem events under DIR_TO_WATCH. When an event
occurs, there is an associated file the event originated at. Those are the
files whose paths FILE_PATTERNs are compared against.
Generally all file system events under DIR_TO_WATCH (with exceptions as
documented for -r and -i and -R) will trigger COMMAND. COMMAND will be run
in the current $SHELL.
Arguments:
DIR_TO_WATCH: indicates the directory whose ancestor file events should
# snipped output
----
=== gotchas
.pesky `bad interpreter: Text file busy`
So you're in terminal a, like:
`$ $EDITOR ./myscript.sh`
... and you're editing, saving, editing, saving, etc.
.and meanwhile, `runonchange` is acting funny:
----
$ runonchange ./myscript.sh # terminal b
# terminal b: meanwhile, *sometimes* you get:
`bash: ./myscript.sh: /bin/bash: bad interpreter: Text file busy``
----
The solution is: terminal b needs to give your bash script a moment on disk
before we ask bash to start parsing the file again:
`$ runonchange 'sleep 0.1; ./myscript.sh'`
Why? I've no clue... Would love to hear from someone on this...
== development
This codebase uses {gomodules}[golang's modules system]. tl;dr is:
----
$ go buld ./... # to recompile your changes
# now a new ./runonchange exec exists
$ go test ./... # to run unit tests
$ go mod tidy # to update dependency changes you've made
----
j/k, there's no unit tests. feel free to add some!
=== origin & copying
This is a port {frombash}[from an old bash script of mine] to Golang.
Also, see `./LICENSE` for copyright.