oh-watch 是一个基于 fs notify 的自动重启工具,当监听到项目中有文件发生修改时,自动重启指定命令。
- 🔍 基于 fs notify 事件变化
- 监听 Create、Modify、Remove 事件
- 📁 支持文件后缀过滤
- 通过 -e go,html 指定监听的文件类型
- 支持忽略规则
- 默认会读取项目跟目录下的
.gitignore文件的配置加入到忽略列表中
- 默认会读取项目跟目录下的
- 🔄 自动重启命令
- 检测到文件变化后自动重启目标进程
- 支持任意命令(如 go run main.go)
- ⚙️ 子进程管理
- 自动停止旧进程
- 监控子进程异常退出并自动重启
cargo install oh-watch或者
cargo install --git https://github.com/oh-rust/oh-watch --branch master#oh-watch -help
Usage: oh-watch [OPTIONS] -- <CMD>...
Arguments:
<CMD>... Command to run (use -- before command)
Options:
-e, --ext <EXT> File extensions to watch (comma-separated),e.g. "js,css", empty = all [default: ""]
-d, --dir <DIR> Dirs to watch (comma-separated) [default: .]
-i, --ignore <IGNORE> [default: **/.*,**/.*/**,**/*.log,**~]
-I, --interval <INTERVAL> Polling interval for checking file changes, in milliseconds [default: 200]
-f, --files <FILES> Additional files to monitor using polling
-b, --build <BUILD> Command to build, option [default: ""]
-h, --help Print help
-V, --version Print versionoh-watch -- go run main.go对于 Go 项目,也可以:
oh-watch -- run
# 相当于
# oh-watch -b "go build" -- ./{app}