智能环境管理工具 | Smart Environment Management Tool
dirauto — Rust 编写的轻量级目录感知环境管理器:进入目录自动加载环境,离开自动清理,让每个项目都有独立的 ENV 与自动化脚本。
- 它是单一职责、纯粹的“目录进出规则控制器”,没有臃肿的插件系统,也不包办一切,只做一件事:让每个项目都有干净、隔离的环境。
- 自动切换:进入目录时自动加载环境,离开时自动清理
- 项目隔离:每个项目独立配置,互不干扰
- 快速响应:Rust 编写,性能卓越
- 简单配置:使用 TOML 格式,通俗易懂
- HOOKS: 支持 on_enter / on_leave 自动执行脚本
# 从源码安装
cargo install dirauto
# 或本地构建
git clone https://github.com/fb0sh/dirauto
cd dirauto
cargo build --release# Bash
eval "$(dirauto hook --shell bash)"
# Zsh
eval "$(dirauto hook --shell zsh)"把上述命令添加到你的 ~/.bashrc 或 ~/.zshrc 文件中。
# 在项目目录创建配置文件
dirauto init这会创建一个 .dirauto.toml 文件,编辑它来配置你的环境:
# Dirauto configuration file
# Environment variables to set when entering this directory
[env]
DIRAUTO_VAR = "dirauto initialized successfully"
# Actions to perform when entering/leaving this directory
[actions]
on_enter = [
"echo 'Entering project directory'",
# "source .venv/bin/activate"
]
on_leave = [
"echo 'Leaving project directory'",
# "deactivate"
]重新加载你的 shell 配置或重启终端,然后验证 dirauto 是否正常工作:
# 检查环境变量
env | grep 'DIRAUTO'你应该能看到类似输出:
DIRAUTO_VERSION=1.0.0
DIRAUTO_OLD_PWD=/home/yourusername
DIRAUTO_SHELL_TYPE=bash现在切换到项目目录,环境会自动加载。离开目录时,环境会自动清理。
dirauto init- 创建配置文件dirauto hook --shell <bash|zsh>- 生成 Shell 钩子dirauto status- 查看当前配置状态
MIT