Created
August 12, 2015 13:24
-
-
Save jabclab/5f2b56405a45118fc944 to your computer and use it in GitHub Desktop.
Go shell helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `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