Created
September 4, 2022 21:25
-
-
Save bergkvist/c8c40ceb8c8365406cb94b11e880550c to your computer and use it in GitHub Desktop.
Watch a file for changes using inotifywait and kill previous process if still running.
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/sh | |
build_and_run() { | |
cc main.c -o main -Wall -Wextra | |
./main | |
} | |
trap 'kill "$p" >/dev/null 2>/dev/null' INT | |
build_and_run & | |
p=$! | |
inotifywait main.c -q -m -e CLOSE_WRITE | | |
while read -r; do | |
kill "$p" >/dev/null 2>/dev/null | |
trap 'kill "$p" >/dev/null 2>/dev/null' INT | |
build_and_run & | |
p=$! | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative using
entr(1)
(which also clears terminal on restart):