A simple, configurable, file watching, job execution tool implemented in Go.
A simple, configurable, file watching, job execution tool implemented in Go.
gawp
ɡɔːp/
verb, British, informal
stare openly in a stupid or rude manner.
go get -u gopkg.in/fsnotify.v1 go get -u gopkg.in/yaml.v2 go get -u github.com/martingallagher/gawp
The following assumes your Go $GOPATH/bin is on your $PATH environmental variable (
export PATH=$PATH:$GOPATH/bin).
By default Gawp attempts to read
.gawpin the active directory. The file format is YAML.
The configuration file location can be set using the
-config my.confcommand-line flag.
Example .gawp file:
recursive: true # Watch directories recursively, default: true verbose: false # Verbose logging, default: false workers: 4 # Number of concurrent workers (high numbers can thrash IO), default: number CPUs / 2 (minimum 1) # logfile: gawp.log # Gawp logfile, default: stdoutstart:
- start myscript
stop:
- echo STOPPING!
write, create, rename: # Actionable events (supported: create, write, rename, remove, chmod), executed sequentially (?i)([a-z]+).src.js$: # Rules are regular expression strings (https://code.google.com/p/re2/wiki/Syntax)
msg=jshint $file
; if [ "$msg" ]; then notify-send -t 2000 "$msg"; fi
java -jar ~/compiler.jar -O=ADVANCED --language_in=ECMASCRIPT5_STRICT --formatting=SINGLE_QUOTES --define='DEBUG=false' --js_output_file=scripts/$1.js $file
(?i)[a-z]+.scss:
compass compile --boring --time -s compressed --css-dir styles/ $file
echo HELLO DENNIS! # Rules can have multiple commands; output is written as-is to the Gawp log
create: .*:
remove: .*:
echo removed $file
Configuration defaults fulfil most user's requirements, resulting in a config file that just defines rules:
write, create, rename: (?i)([a-z]+)\.src\.js$:
msg=jshint $file
; if [ "$msg" ]; then notify-send -t 2000 "$msg"; fi
java -jar ~/compiler.jar -O=ADVANCED --language_in=ECMASCRIPT5_STRICT --formatting=SINGLE_QUOTES --define='DEBUG=false' --js_output_file=scripts/$1.js $file
(?i)[a-z]+.scss:
compass compile --boring -s compressed --css-dir styles/ $file
create: .*:
remove: .*:
Assuming correctly configured
web/assets/.gawpfile:
cd web/assets/ && gawp
Some IDE's e.g. NetBeans, perform "atomic" saves. Gawp attempts to detect such operations, running the matching rule commands only once. The threshold duration setting for detecting atomic saves
atomicthresholdcan be adjusted if you find it is too liberal/conservative for your underlying storage.
Gawp does no command validation. It pre-processes them, replacing variables and executes blindly. Rules can contain subcommands, which is useful when you need to use subcommand results. For example, on Linux/Ubuntu you might wish to lint the edits to your JavaScript files and create an alert via
notify-send:
write: (?i)([a-z]+)\.src\.js$: - msg=`jshint $file`; if [ "$msg" ]; then notify-send -t 2000 "$msg"; fi
If there's output from
jshint, a notification bubble will be displayed to the user with the result.
Bug fixes and feature requests welcome.