Commit f3eb9a22 authored by bbguimaraes's avatar bbguimaraes
Browse files

Added support for inotify on auto_make.

inotify doesn't work over nfs (/sshfs), so the "sleep" version has been
kept as the default. New features can be used by adding flags "-i" or
"--inotify".
parent 9c811f27
#!/bin/bash
# Run make every second, but only if necessary. Arguments are forwarded to make
# -q and make.
MAKE=make
MAKE_TEST="$MAKE -q"
wait_for_event() {
inotifywait -qqr -e modify -e attrib .
}
log() {
[ "$VERBOSE" -lt $1 ] && return
shift
echo "$@"
}
args="$(getopt -o inv --longoptions inotify,notify,verbose -- "$@")"
getopt_exit="$?"
if [ "$getopt_exit" -ne 0 ]; then
echo "$args" >&2
exit "$getopt_exit"
fi
eval set -- "$args"
VERBOSE=0
while true; do
case "$1" in
-i|--inotify) USE_INOTIFY=1; shift ;;
-n|--notify) USE_NOTIFY=1; shift ;;
-v|--verbose) VERBOSE=$((VERBOSE + 1)); shift ;;
--) shift; break ;;
esac
done
make=make
make_test=$make\ -q
while true; do
if ! $make_test "$@"; then
echo making...
$make "$@"
echo made
notify-send -t 1000 make made
sleep 1s
[ "$USE_INOTIFY" ] && ( log 2 'Waiting for event...'; wait_for_event )
if ! $MAKE_TEST "$@"; then
log 1 'making...'
$MAKE "$@"
make_exit="$?"
[ "$make_exit" -eq 0 ] || log 1 "Make exit code: $make_exit"
log 1 'made'
[ "$USE_NOTIFY" ] && notify-send -t 1000 make made
[ ! "$USE_INOTIFY" ] && ( log 2 'Waiting a second...'; sleep 1s )
fi
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment