Skip to content

Instantly share code, notes, and snippets.

@jabclab
Created August 12, 2015 13:24
Show Gist options
  • Save jabclab/5f2b56405a45118fc944 to your computer and use it in GitHub Desktop.
Save jabclab/5f2b56405a45118fc944 to your computer and use it in GitHub Desktop.
Go shell helpers
# `go watch` - Watch files and run tests on change. Report to terminal and OSX notification.
# `go watchq` - Watch files and run tests on change (without -v). Report to terminal and OSX notification.
# `go cover` - Obtain test coverage and show results in default browser.
#
# dependencies:
# * `fswatch` - https://github.com/emcrisostomo/fswatch
# * `terminal-notifier` - https://github.com/julienXX/terminal-notifier
go() {
case $1 in
# Watch files and show display test results in the shell and via
# terminal-notifier.
'watch')
cmd="res=\$(go test -v 2>&1); [[ \$? -eq 0 ]] && status='PASS' || status='FAIL'; echo -e \"*******************************\n\$res\"; terminal-notifier -message \"\$status\" -title 'Go test' -contentImage http://synflood.at/tmp/golang-slides/images/gophercolor.png"
fswatch ./*.go | xargs -n1 bash -c "$cmd"
;;
# Watch files and show display test results in the shell and via
# terminal-notifier (no -v used for `go test`).
'watchq')
cmd="res=\$(go test 2>&1); [[ \$? -eq 0 ]] && status='PASS' || status='FAIL'; echo -e \"*******************************\n\$res\"; terminal-notifier -message \"\$status\" -title 'Go test' -contentImage http://synflood.at/tmp/golang-slides/images/gophercolor.png"
fswatch ./*.go | xargs -n1 bash -c "$cmd"
;;
# Obtain test coverage and open in the default browser.
'cover')
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
;;
# Pass through option to `go` CLI.
*)
command go "$@"
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment