While writing Go projects, I realized there were certain commands I always executed in another terminal after any changes to the codebase:
$ go build $ go vet $ go test
This was ok to run once or twice, but after a while it became very repetive and although my editor supports
go fmt and
go vet checks after file saves, when it came to running other build steps it wasn’t so easy.
Steven Berlanga and I started discussing a simple concept of watching file changes and executing these commands. This is where snag comes in. Initially designed to run commands specific to Go, it was expanded to be more flexible to run arbitrary commands. This flexibility allowed customization on a per-project level and best of all, it didn’t require any particular language to be executed.
Let’s get snaggin’
Snag works by reading a
.snag.yml file in the project that you wish to watch. The file uses yaml synax and contains three sections:
The script section contains an array of commands to execute. Each of these commands will execute serially and if one command fails (non-zero exit status), the execution of the remaining commands will halt.
The ignore section is useful when you don’t want snag to watch certain files or folders. It contains an array of files or folders that snag will skip over when watching for changes.
The verbose section is used to see the output of commands even when they are successful. By default, snag will only output a command’s output if it fails.
A sample snag file looks like this:
script: - echo "hello world" - go test ignore: - .git - myfile.ext verbose: true
snag in the folder that contains this file will execute the directives as stated above.
Go snag it!
Snag releases can be found on the releases section. Simply pick the binary for the correct OS and Architecture.
If you’re on OSX and use Homebrew run:
brew update && brew install snag
There are future version plans for the tool. Stars, feedback and suggestions are greatly appreciated. Go ahead and give it a try! Snag Github