runonchange

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0

README

= Run Command On Changes
:frombash: https://github.com/jzacsh/bin/blob/f38719fdc6795/share/runonchange
:locref: https://github.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 github.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.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL