Skip to content

Instantly share code, notes, and snippets.

@maugre
Last active December 11, 2017 16:11
Show Gist options
  • Save maugre/e39f965689abe264ec7f164c5cb3f268 to your computer and use it in GitHub Desktop.
Save maugre/e39f965689abe264ec7f164c5cb3f268 to your computer and use it in GitHub Desktop.
Rebuild a Go project when a code change is detected.
#!/usr/bin/env bash
P=`pwd`
BUILDNAME=/tmp/${P##*/}-build
function goRun() {
echo "-- Building..."
## Build new binary
go build -i -o $BUILDNAME ./cmd/frontend/*.go
## Kill previous and run new binary
if [[ $? -eq 0 ]];
then
killall -q ${BUILDNAME##*/}
$BUILDNAME &
VAR=$!
echo "Started process" $VAR
fi
}
while true
do
goRun
## Wait
inotifywait -qre close_write,modify,move --include '[.*](go|tpl)$' .
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment