Snag
An automatic build tool for all your needs
Installation
Releases
You can visit the releases section to download the binary for your platform.
Homebrew
We've got a formula in homebrew!
brew update && brew install snag
Source
If you have go installed and want to install the latest and greatest you can run:
$ go get github.com/Tonkpils/snag
Usage
Snag works by reading a yaml file named .snag.yml
. It allows you to configure what snag will
run and what it should ignore. The file must reside in the same
directory that you want to watch.
Here is a sample of a .snag.yml
file:
script:
- echo "hello world"
- go test
ignore:
- .git
- "**.ext"
- "foo/**/bar.sh"
verbose: true
By default, snag will watch all files/folders within the current directory recursively. The ignore section will tell snag to ignore any changes that happen to the directories/files listed. The ignore section uses the same pattern matching that gitignore uses.
The script section of the file will be executed when any file is created, deleted, or modified.
Simply run:
snag
From a project with a .snag.yml
file and develop away!
Quick Use
If you find yourself working on a project that does not contain a snag file and still want to use snag, you can use flags to specify commands to run.
The -c
flag allows specifying a command just like the snag file and can
be defined more than once for multiple commands. The order of the commands
depends on the order of the flag.
snag -c "echo snag world" -c "echo rocks"
will output
|Passed | echo snag world
|Passed | echo rocks
The -v
flag enables verbose output. It will also override the verbose
option form the snag file if it is defined to false.
NOTE: using the -c
flag will skip reading a snag file even if it
exists in the current working directory.
Environment Variables
You can access your shell's environment variables by using $$
.
script:
- echo $$MY_VAR
- rm -rf $$OUTPUT_DIR
Caveats
Endless build loops
Snag will run your configured scripts if ANY file modifed in your current directory.
If you scripts generate any files, you should add them to the ignore
section in your
.snag.yml
to avoid an endless build loop.
Trouble running shell scripts
In order to run shell scripts, your must have a shebang in it. If you are trying to run a script without a shebang, you will need to specify the shell it should run in.
i.e.
Running a script with a shebang
scripts:
- ./my-script
Running a script without a shebang
scripts:
- bash my-script
Ignore Pattern Matching
If you want to use asterisks in the ignore section of you snag.yml, you need to make sure to wrap them in quotes or you may run into an error like:
$ snag
2015/10/24 19:39:40 Could not parse yml file. yaml: line 6: did not find expected alphabetic or numeric character
Known Issues
open /dev/null: too many open files
You may experience this error if you're running on OSX. You may need to bump the maximum number of open file on your machine. You can refer to this article for more information on the max files on OSX and this superuser post for a solution