Skip to content

Instantly share code, notes, and snippets.

@carbocation
Last active February 14, 2016 18:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save carbocation/5278173 to your computer and use it in GitHub Desktop.
Save carbocation/5278173 to your computer and use it in GitHub Desktop.
On OS X, use fswatch to automatically recompile your golang project whenever you change a file in the directory.
#!/bin/bash
# This script keeps watch on the current project and compiles it continuously as you change files.
# If there are multiple projects with the same final directory name (e.g., /proj/rad and /lib/monster/rad),
# this will kill any other similarly-named running projects' binaries, potentially leading to havoc.
# To run, install fswatch, drop this file into your project directory, make it executable, and run:
# /usr/local/bin/fswatch ./ ./continuous-compile.sh
echo "Re-compiling"
#Count the number of times the compiled app is running
numproc=`ps aux | grep ${PWD##*/}-main.osx | grep -v grep | wc -l`
if [[ numproc > 0 ]]
then
killall ${PWD##*/}-main.osx 2> /dev/null
fi
go build -o /tmp/${PWD##*/}-main.osx main.go && /tmp/${PWD##*/}-main.osx &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment