dirauto

Crates.iodirauto
lib.rsdirauto
version1.1.0
created_at2025-12-11 08:26:43.648618+00
updated_at2025-12-11 11:38:37.960814+00
descriptionA direnv-like tool with strategy pattern for shell hooks
homepage
repositoryhttps://github.com/fb0sh/dirauto
max_upload_size
id1979368
size40,908
fb0sh (fb0sh)

documentation

README

dirauto

智能环境管理工具 | Smart Environment Management Tool

Crates.io Rust License: MIT

English | 中文


简介

dirauto 是一个智能的环境管理工具,可以根据你所在的目录自动加载和卸载环境变量,还能通过 hook 执行自定义脚本。每个项目可以有自己独立的环境配置和自动化脚本,无需手动设置。

特性

  • 自动切换:进入目录时自动加载环境,离开时自动清理
  • 项目隔离:每个项目独立配置,互不干扰
  • 快速响应:Rust 编写,性能卓越
  • 简单配置:使用 TOML 格式,通俗易懂

演示

asciicast

快速开始

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

Commit count: 0

cargo fmt