Simple Reloading Server in Bash
It’s often extremely useful to have a server that automatically reloads when any of the source files change. Grunt is commonly used for this, but in some cases that is overkill - a simple bash script will suffice. The script below uses Python 2 to start the server and inotify-utils to wait on changes in a directory.
#!/bin/sh
set -e
# Create site dir if it does not exist
mkdir -p site
# Python server
cd site
python -m SimpleHTTPServer &
cd ..
# Kill python server on exit
trap "exit" INT TERM
trap "kill 0" EXIT
while true; do
echo "Building site..."
sass theme/styles.scss:theme/styles.css
python2 buildsite.py
echo "Waiting for changes..."
inotifywait -e modify -r .
done