DEV Community

Omar
Omar

Posted on

I built a file watcher in Rust

You know the loop.

Save. Switch to terminal. Up arrow. Enter. Wait. Switch back. Repeat forever.

I got tired of it so I built fyr, a file watcher that kills the ritual.


The basics

fyr -w src -r "cargo run"
Enter fullscreen mode Exit fullscreen mode

Save a file inside /src, fyr runs your command. Previous run still going? It kills it first. No stale processes, no duplicate output. Just a clean run every time.


Tasks system

fyr task add build -w src -r "cargo build --release"
fyr run build
Enter fullscreen mode Exit fullscreen mode

Save it once, run it from anywhere. No more remembering flags.

You can also drop a fyr.toml in your project and commit it, so everyone on the team gets the same setup for free:

[tasks.build]
watch = ["src"]
run = "cargo build --release"

[tasks.test]
watch = ["src", "tests"]
run = "cargo test"
Enter fullscreen mode Exit fullscreen mode

How it stacks up

Benchmarked against the popular alternatives:

Tool Startup Idle memory
fyr 219ms 7.6 MB
watchexec 238ms 13.5 MB
chokidar 501ms 37.6 MB
nodemon 528ms 41.2 MB

GitHub: https://github.com/opmr0/fyr

Would love to hear what you think, especially if you've used watchexec or cargo-watch before.

Top comments (0)