Skip to content

Instantly share code, notes, and snippets.

@codebrainz
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save codebrainz/69b8df344481b51112c5 to your computer and use it in GitHub Desktop.

Select an option

Save codebrainz/69b8df344481b51112c5 to your computer and use it in GitHub Desktop.
Run build system when sources change
#!/bin/bash
# Inspired by: https://exyr.org/2011/inotify-run/
# base source dir, found from script's dir, in my case it's `..` to the base srcdir
SRCDIR=$(cd "$(dirname $(dirname "$0"))"; pwd -P)
# command to run initially and on file changes, in my case in `build` dir
COMMAND="make -C $SRCDIR/build"
# message to print before running command
FORMAT="Running \`$COMMAND' ..."
# run once right away
echo "$FORMAT"
$COMMAND
# keep running when some files change
while inotifywait -qre close_write --format "$FORMAT" "$SRCDIR/sodac"
do
$COMMAND
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment