Skip to content

Sherly1001/watch.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Watch.sh

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 or Ctrl-C to stop watching.

Install

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

Example

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
}

Known issues

  • 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.

About

Watch file changes and auto recompile

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages