]> git.donarmstrong.com Git - bin.git/commitdiff
add new run when changed command
authorDon Armstrong <don@donarmstrong.com>
Fri, 28 Apr 2017 20:20:11 +0000 (13:20 -0700)
committerDon Armstrong <don@donarmstrong.com>
Fri, 28 Apr 2017 20:30:55 +0000 (13:30 -0700)
run_when_changed [new file with mode: 0755]

diff --git a/run_when_changed b/run_when_changed
new file mode 100755 (executable)
index 0000000..85c4c34
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+WATCH_FILE="$1"
+shift 1;
+
+WATCH_DIR=`dirname "$WATCH_FILE"`
+WATCH_FILE=`basename "$WATCH_FILE"`
+
+inotifywait -m -e close_write,moved_to,create $WATCH_DIR |
+    while read -r directory events filename; do
+        if [ "x$filename" = "x$WATCH_FILE" ]; then
+            ( exec "$@" );
+        fi;
+    done;