配置

忽略文件

通过在项目中创建 `.bobignore` 文件,控制 Bob Shell 可以访问的文件。

概述

功能描述优势
路径排除阻止 Bob Shell 访问特定文件或目录保护敏感信息
模式匹配使用 glob 模式匹配多个文件高效排除文件类型
否定支持覆盖特定文件的排除规则精细化控制
项目专属每个项目可拥有自己的排除规则按项目定制

为什么使用 .bobignore?

  • 隐私保护:保持 API key 和凭据等敏感文件的私密性
  • 性能提升:排除会拖慢操作的大型二进制文件或目录
  • 减少干扰:从 Bob Shell 的上下文中移除不相关的文件
  • 焦点控制:将 Bob Shell 的注意力引导到代码库中最相关的部分

.bobignore 的工作原理

当您向 .bobignore 文件添加路径时,遵守该文件的 Bob Shell 工具将自动从其操作中排除匹配的文件和目录。例如,使用 read_many_files 命令时,.bobignore 文件中的路径将被跳过。

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│                 │     │                 │     │                 │
│  Your project   │────▶│  .bobignore     │────▶│  Files Bob Shell │
│  files          │     │  filter         │     │  can access     │
│                 │     │                 │     │                 │
└─────────────────┘     └─────────────────┘     └─────────────────┘

.bobignore 文件的更改需要重新启动 Bob Shell 会话才能生效。

模式语法

.bobignore 文件遵循与 .gitignore 相同的模式语法:

模式描述示例
file.txt匹配特定文件apikeys.txt
*.ext匹配所有具有该扩展名的文件*.log
/dir/匹配目录/node_modules/
/path/to/file将路径锚定到根目录/src/config/secrets.json
!pattern否定之前的模式!important.md
#注释行# API credentials

快速上手

创建 .bobignore 文件

  1. 在项目根目录中创建一个名为 .bobignore 的文件
  2. 添加要排除的文件和目录的模式
  3. 保存文件并重新启动 Bob Shell 会话
# 在项目根目录中执行
touch .bobignore
echo "# Files to ignore" > .bobignore
echo "secrets/" >> .bobignore

常用排除模式

以下是您可能希望添加到 .bobignore 文件中的一些常用模式:

# Sensitive information
.env
secrets/
*password*
*credential*
*apikey*

# Large directories
node_modules/
.git/
dist/
build/

# Binary and media files
*.zip
*.tar.gz
*.mp4
*.jpg
*.png

# Log files
*.log
logs/

模式示例

排除特定目录

要排除整个目录及其内容:

# Exclude the packages directory and all its contents
/packages/

# Exclude all node_modules directories anywhere in the project
**/node_modules/

# Exclude the dist directory but only at the root level
/dist/

使用通配符

通配符允许您用相似的模式匹配多个文件:

# Exclude all markdown files
*.md

# Exclude all JavaScript files in the src directory
/src/**/*.js

# Exclude all files with "test" in their name
*test*

使用否定

您可以为特定文件覆盖排除规则:

# Exclude all markdown files
*.md

# But include README.md
!README.md

# And include all markdown files in the docs directory
!docs/*.md

高级用法

组合模式

您可以通过组合模式创建复杂的排除规则:

# Exclude all JavaScript files
*.js

# But include all files in the src directory
!src/**/*.js

# Except for test files in the src directory
src/**/*.test.js

调试 .bobignore 文件

如果 Bob Shell 似乎忽略了您希望它访问的文件,或者访问了您希望它忽略的文件:

  1. 检查 .bobignore 文件中是否存在冲突的模式
  2. 记住更具体的模式(如否定)应放在通用模式之后
  3. 修改后重新启动 Bob Shell 会话
  4. 如果相对路径不起作用,请使用绝对路径

最佳实践

  • 从简单开始:先添加几个基本模式,然后根据需要添加更多
  • 为模式添加注释:添加注释说明为什么要排除某些文件
  • 保持精确:使用精确的模式,避免意外排除重要文件
  • 考虑安全性:始终排除包含敏感信息的文件
  • 定期维护:随着项目的演进更新 .bobignore 文件
这个主题怎么样?