Last active
April 7, 2016 12:07
-
-
Save JSila/5f1c9595394b5c85236d to your computer and use it in GitHub Desktop.
Bash script for building and starting application written in Go. Also if some file is changed, it rebuilds and restarts application.
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
#!/bin/bash | |
# Bash script for building and starting application in Go. Also if some file is changed, it rebuilds and restarts application. | |
# Before running the script, inotify-tools has to be installed. | |
trap ctrl_c INT | |
function ctrl_c { | |
kill $PID | |
log "stopped" | |
exit | |
} | |
APPNAME=${PWD##*/} | |
YELLOW=$(tput setaf 3) | |
RESET=$(tput sgr0) | |
function log { | |
echo "${YELLOW}${1} ${APPNAME}${RESET}" | |
} | |
function run { | |
if [[ -n "$PID" ]]; then kill $PID; fi | |
./$APPNAME & | |
PID=$! | |
} | |
function build { | |
go build . | |
} | |
build | |
log "built and started" | |
run | |
while true; do | |
change=$(inotifywait --quiet -e close_write,moved_to,create .) | |
file=${change#./ * } | |
if [[ ${file##*.} = go ]]; then | |
build | |
log "rebuilt and restared" | |
run | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment