A simple script to watch for file changes in the project, enabling automatic recompilation and execution.
Just do: watch.sh
- type
bs
to rebuild the project. - type
rs
to rerun the built program. - type
exit
orCtrl-C
to 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.sh
Create 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_cmd
returns false (return code != 0): this will break the while loop when watching file changes. Therefore,watch_cmd
should return true after detecting file changes.