A simple script to watch for file changes in the project, enabling automatic recompilation and execution.
Just do: watch.sh
- type
bsto rebuild the project. - type
rsto rerun the built program. - type
exitorCtrl-Cto stop watching.
sudo curl -sL https://raw.githubusercontent.com/Sherly1001/watch.sh/main/watch.sh -o /usr/local/bin/watch.sh
sudo chmod +x /usr/local/bin/watch.shCreate a file named watch.cfg.sh inside the root directory of your project and define three commands: build_cmd, run_cmd, and watch_cmd.
# watch.cfg.sh
build_cmd() {
meson compile -C build
}
run_cmd() {
./build/main
}
watch_cmd() {
inotifywait -e modify -r src include meson.build
}watch_cmdreturns false (return code != 0): this will break the while loop when watching file changes. Therefore,watch_cmdshould return true after detecting file changes.