Created
February 19, 2018 00:07
-
-
Save cstockton/ae2dedf3730b27b0d0d96ee402d693ee to your computer and use it in GitHub Desktop.
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
function _alias_wgo() { | |
W_PROG=$1 | |
W_ARGS="${@:2}" | |
W_WATCH="${W_WATCH:-.}" | |
W_EXT="${W_EXT:-py|go|tpl|sh|md|txt}" | |
W_IGNORE="${W_IGNORE:-vendor,envs,log,.git}" | |
# look for go package | |
go list >/dev/null 2>&1 && { | |
W_PROG="go" | |
W_ARGS="${@:1}" | |
# Run main? | |
W_ARGS="${W_ARGS:-$(grep '^func main(' *.go|head -1|awk -F\: '{print $1}'|xargs -r printf 'run %s')}" | |
# Run tests? | |
W_ARGS="${W_ARGS:-$(ls *_test.go | grep -q . && echo 'test')}" | |
} | |
[ -z "${W_PROG}" ] && { echo >&2 "invalid context, pass a program to run"; return; } | |
echo | |
echo "=========== ctx ===========" | |
echo "W_PROG: ${W_PROG}" | |
echo "W_ARGS: ${W_ARGS}" | |
echo "W_WATCH: ${W_WATCH}" | |
echo "W_EXT: ${W_EXT}" | |
echo "W_IGNORE: ${W_IGNORE}" | |
echo | |
echo "=========== run ===========" | |
csnotify \ | |
-n 'exit' \ | |
-e "${W_EXT}" \ | |
-w "${W_WATCH}" \ | |
-i "${W_IGNORE}" \ | |
-- "${W_PROG}" $W_ARGS | |
echo | |
echo "=========== end ===========" | |
echo | |
} | |
alias wgo=_alias_wgo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment