| Crates.io | dirauto |
| lib.rs | dirauto |
| version | 1.1.0 |
| created_at | 2025-12-11 08:26:43.648618+00 |
| updated_at | 2025-12-11 11:38:37.960814+00 |
| description | A direnv-like tool with strategy pattern for shell hooks |
| homepage | |
| repository | https://github.com/fb0sh/dirauto |
| max_upload_size | |
| id | 1979368 |
| size | 40,908 |
智能环境管理工具 | Smart Environment Management Tool
dirauto 是一个智能的环境管理工具,可以根据你所在的目录自动加载和卸载环境变量,还能通过 hook 执行自定义脚本。每个项目可以有自己独立的环境配置和自动化脚本,无需手动设置。
# 从源码安装
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