3 stable releases
Uses new Rust 2024
| 1.1.0 | Dec 11, 2025 |
|---|---|
| 1.0.1 | Dec 11, 2025 |
#4 in #编写
19KB
359 lines
dirauto
智能环境管理工具 | Smart Environment Management Tool
简介
dirauto 是一个智能的环境管理工具,可以根据你所在的目录自动加载和卸载环境变量,还能通过 hook 执行自定义脚本。每个项目可以有自己独立的环境配置和自动化脚本,无需手动设置。
特性
- 自动切换:进入目录时自动加载环境,离开时自动清理
- 项目隔离:每个项目独立配置,互不干扰
- 快速响应:Rust 编写,性能卓越
- 简单配置:使用 TOML 格式,通俗易懂
演示
快速开始
1. 安装
# 从源码安装
cargo install dirauto
# 或本地构建
git clone https://github.com/fb0sh/dirauto
cd dirauto
cargo build --release
2. 配置 Shell
# Bash
eval "$(dirauto hook --shell bash)"
# Zsh
eval "$(dirauto hook --shell zsh)"
把上述命令添加到你的 ~/.bashrc 或 ~/.zshrc 文件中。
3. 创建配置
# 在项目目录创建配置文件
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"
]
4. 验证配置
重新加载你的 shell 配置或重启终端,然后验证 dirauto 是否正常工作:
# 检查环境变量
env | grep 'DIRAUTO'
你应该能看到类似输出:
DIRAUTO_VERSION=1.0.0
DIRAUTO_OLD_PWD=/home/yourusername
DIRAUTO_SHELL_TYPE=bash
5. 完成!
现在切换到项目目录,环境会自动加载。离开目录时,环境会自动清理。
命令说明
dirauto init- 创建配置文件dirauto hook --shell <bash|zsh>- 生成 Shell 钩子dirauto status- 查看当前配置状态
License
MIT
Dependencies
~2–14MB
~114K SLoC