Skip to content

Instantly share code, notes, and snippets.

@cstockton
Created February 19, 2018 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cstockton/ae2dedf3730b27b0d0d96ee402d693ee to your computer and use it in GitHub Desktop.
Save cstockton/ae2dedf3730b27b0d0d96ee402d693ee to your computer and use it in GitHub Desktop.
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