unix-goto-development
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseunix-goto Development Expert
unix-goto开发专家
Comprehensive development expertise for the unix-goto shell navigation system - a high-performance Unix navigation tool with natural language support, sub-100ms cached navigation, and 100% test coverage.
为unix-goto shell导航系统提供全面的开发专业指导——这是一款高性能Unix导航工具,支持自然语言、缓存导航耗时低于100ms,且测试覆盖率达100%。
When to Use This Skill
何时使用本技能
Use this skill when:
- Developing new features for unix-goto shell navigation system
- Implementing cache-based navigation optimizations
- Adding bookmarks, history, or navigation commands
- Following the standard 9-step feature addition workflow
- Integrating with Linear project management
- Writing comprehensive test suites (100% coverage required)
- Optimizing performance to meet <100ms targets
- Creating API documentation for shell modules
- Debugging navigation or cache issues
Do NOT use this skill for:
- General bash scripting (use generic bash skills)
- Non-navigation shell tools
- Projects without performance requirements
- Simple one-off shell scripts
在以下场景使用本技能:
- 为unix-goto shell导航系统开发新功能
- 实现基于缓存的导航优化
- 添加书签、历史记录或导航命令
- 遵循标准的9步功能添加流程
- 与Linear项目管理工具集成
- 编写全面的测试套件(要求100%覆盖率)
- 优化性能以满足<100ms的目标
- 为shell模块创建API文档
- 调试导航或缓存相关问题
请勿在以下场景使用本技能:
- 通用bash脚本开发(使用通用bash技能)
- 非导航类shell工具
- 无性能要求的项目
- 简单的一次性shell脚本
Project Overview
项目概述
unix-goto System Architecture
unix-goto系统架构
unix-goto is a high-performance Unix navigation system designed with five core principles:
- Simple - ONE-line loading (), minimal configuration
source goto.sh - Fast - Sub-100ms navigation performance
- Lean - No bloat, no unnecessary dependencies
- Tested - 100% test coverage for core features
- Documented - Clear, comprehensive documentation
unix-goto是一款高性能Unix导航系统,遵循五大核心原则:
- 简洁 - 一行命令加载(),配置极简
source goto.sh - 快速 - 导航性能耗时低于100ms
- 轻量 - 无冗余,无不必要依赖
- 可测试 - 核心功能测试覆盖率达100%
- 文档完善 - 清晰全面的文档
Key Performance Metrics
关键性能指标
| Metric | Target | Achieved | Status |
|---|---|---|---|
| Cached navigation | <100ms | 26ms | ✅ Exceeded |
| Cache hit rate | >90% | 92-95% | ✅ Exceeded |
| Speedup ratio | 20-50x | 8x | ⏳ On track |
| Test coverage | 100% | 100% | ✅ Met |
| Cache build time | <5s | 3-5s | ✅ Met |
| 指标 | 目标 | 已达成 | 状态 |
|---|---|---|---|
| 缓存导航耗时 | <100ms | 26ms | ✅ 超出预期 |
| 缓存命中率 | >90% | 92-95% | ✅ 超出预期 |
| 加速比 | 20-50x | 8x | ⏳ 进行中 |
| 测试覆盖率 | 100% | 100% | ✅ 达标 |
| 缓存构建时间 | <5s | 3-5s | ✅ 达标 |
System Architecture
系统架构
┌─────────────────────────────────────────────────────────────┐
│ User Interface │
│ goto, bookmark, recent, back, goto list, goto benchmark │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Core Navigation │
│ goto-function.sh - Main routing and path resolution │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────┼─────────────────┐
▼ ▼ ▼
┌──────────────────┐ ┌──────────────┐ ┌──────────────────┐
│ Cache System │ │ Bookmarks │ │ History │
│ cache-index.sh │ │ bookmark- │ │ history- │
│ │ │ command.sh │ │ tracking.sh │
│ O(1) lookup │ │ │ │ │
│ Auto-refresh │ │ Add/Remove │ │ Track visits │
└──────────────────┘ └──────────────┘ └──────────────────┘┌─────────────────────────────────────────────────────────────┐
│ User Interface │
│ goto, bookmark, recent, back, goto list, goto benchmark │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Core Navigation │
│ goto-function.sh - Main routing and path resolution │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────┼─────────────────┐
▼ ▼ ▼
┌──────────────────┐ ┌──────────────┐ ┌──────────────────┐
│ Cache System │ │ Bookmarks │ │ History │
│ cache-index.sh │ │ bookmark- │ │ history- │
│ │ │ command.sh │ │ tracking.sh │
│ O(1) lookup │ │ │ │ │
│ Auto-refresh │ │ Add/Remove │ │ Track visits │
└──────────────────┘ └──────────────┘ └──────────────────┘Module Dependencies
模块依赖
Critical Load Order (dependencies must load before dependents):
goto.sh (loader)
├── history-tracking.sh (no dependencies)
├── back-command.sh (depends on: history-tracking.sh)
├── recent-command.sh (depends on: history-tracking.sh)
├── bookmark-command.sh (no dependencies)
├── cache-index.sh (no dependencies)
├── list-command.sh (depends on: bookmark-command.sh)
├── benchmark-command.sh (depends on: cache-index.sh)
├── benchmark-workspace.sh (no dependencies)
└── goto-function.sh (depends on: all above)关键加载顺序(依赖模块必须先于被依赖模块加载):
goto.sh (loader)
├── history-tracking.sh (no dependencies)
├── back-command.sh (depends on: history-tracking.sh)
├── recent-command.sh (depends on: history-tracking.sh)
├── bookmark-command.sh (no dependencies)
├── cache-index.sh (no dependencies)
├── list-command.sh (depends on: bookmark-command.sh)
├── benchmark-command.sh (depends on: cache-index.sh)
├── benchmark-workspace.sh (no dependencies)
└── goto-function.sh (depends on: all above)Core Knowledge
核心知识
The 9-Step Feature Addition Workflow
9步功能添加流程
This is the STANDARD process for adding any feature to unix-goto. Follow ALL nine steps.
这是为unix-goto添加任何功能的标准流程,必须遵循全部9个步骤。
Step 1: Plan Your Feature
步骤1:规划功能
Before writing ANY code, answer these questions:
Planning Questions:
- What problem does this solve?
- What's the user interface (commands/flags)?
- What's the expected performance?
- What dependencies exist?
- What tests are needed?
- What documentation is required?
Planning Template:
Feature: [Name]
Problem: [User pain point]
Interface: [Commands/flags]
Performance: [Target metrics]
Dependencies: [Module dependencies]
Tests: [Test scenarios]
Docs: [API.md, README.md sections]Example - Recent Directories Feature (CET-77):
Feature: Recent Directories Command
Problem: Users can't quickly revisit recently navigated directories
Interface: goto recent [n]
Performance: <10ms for history retrieval
Dependencies: history-tracking.sh
Tests:
- List recent directories
- Handle empty history
- Limit to N entries
- Navigate to recent directory by number
Docs: Add to API.md and README.md在编写任何代码之前,先回答以下问题:
规划问题:
- 该功能解决什么问题?
- 用户界面是什么(命令/参数)?
- 预期性能如何?
- 存在哪些依赖?
- 需要哪些测试?
- 需要编写哪些文档?
规划模板:
Feature: [功能名称]
Problem: [用户痛点]
Interface: [命令/参数]
Performance: [目标指标]
Dependencies: [模块依赖]
Tests: [测试场景]
Docs: [API.md、README.md中的对应章节]示例 - 最近访问目录功能(CET-77):
Feature: 最近访问目录命令
Problem: 用户无法快速重新访问最近导航过的目录
Interface: goto recent [n]
Performance: 历史记录检索耗时<10ms
Dependencies: history-tracking.sh
Tests:
- 列出最近访问的目录
- 处理空历史记录
- 限制显示N条记录
- 通过编号导航到最近访问的目录
Docs: 添加到API.md和README.mdStep 2: Create Module (if needed)
步骤2:创建模块(如需要)
Module Template:
bash
#!/bin/bash模块模板:
bash
#!/bin/bashunix-goto - [Module purpose]
unix-goto - [模块用途]
Storage location
存储位置
GOTO_MODULE_FILE="${GOTO_MODULE_FILE:-$HOME/.goto_module}"
GOTO_MODULE_FILE="${GOTO_MODULE_FILE:-$HOME/.goto_module}"
Main function
主函数
goto_module() {
local subcommand="$1"
shift
case "$subcommand" in
list)
# Implementation
;;
add)
# Implementation
;;
--help|-h|help|"")
echo "goto module - [Description]"
echo ""
echo "Usage:"
echo " goto module list [Description]"
echo " goto module add [Description]"
;;
*)
echo "Unknown command: $subcommand"
return 1
;;
esac}
**Key Module Patterns:**
1. **Function Naming:**
- Public functions: no prefix (`goto`, `bookmark`, `recent`)
- Internal functions: double underscore (`__goto_navigate_to`, `__goto_cache_lookup`)
- Variables: UPPERCASE for globals, lowercase for locals
2. **Environment Variables:**
```bash
# Always provide defaults
GOTO_INDEX_FILE="${GOTO_INDEX_FILE:-$HOME/.goto_index}"
GOTO_CACHE_TTL="${GOTO_CACHE_TTL:-86400}"
GOTO_SEARCH_DEPTH="${GOTO_SEARCH_DEPTH:-3}"- Return Codes:
- - Success
0 - - General error (not found, invalid input)
1 - - Multiple matches found (cache lookup only)
2
goto_module() {
local subcommand="$1"
shift
case "$subcommand" in
list)
# 实现代码
;;
add)
# 实现代码
;;
--help|-h|help|"")
echo "goto module - [描述]"
echo ""
echo "用法:"
echo " goto module list [描述]"
echo " goto module add [描述]"
;;
*)
echo "未知命令: $subcommand"
return 1
;;
esac}
**关键模块模式:**
1. **函数命名:**
- 公共函数:无前缀(`goto`, `bookmark`, `recent`)
- 内部函数:双下划线前缀(`__goto_navigate_to`, `__goto_cache_lookup`)
- 变量:全局变量使用大写,局部变量使用小写
2. **环境变量:**
```bash
# 始终提供默认值
GOTO_INDEX_FILE="${GOTO_INDEX_FILE:-$HOME/.goto_index}"
GOTO_CACHE_TTL="${GOTO_CACHE_TTL:-86400}"
GOTO_SEARCH_DEPTH="${GOTO_SEARCH_DEPTH:-3}"- 返回码:
- - 成功
0 - - 通用错误(未找到、输入无效)
1 - - 找到多个匹配项(仅缓存查找)
2
Step 3: Add to Loader
步骤3:添加到加载器
Edit to load your module in the correct dependency order:
goto.shbash
undefined编辑,按照正确的依赖顺序加载你的模块:
goto.shbash
undefinedAdd to load sequence (respect dependencies)
添加到加载序列(遵循依赖规则)
source "$GOTO_LIB_DIR/history-tracking.sh"
source "$GOTO_LIB_DIR/module.sh" # NEW - add after dependencies
source "$GOTO_LIB_DIR/back-command.sh"
**Dependency Rules:**
- Modules with no dependencies load first
- Modules depending on others load AFTER dependencies
- Main goto-function.sh loads LAST (depends on everything)source "$GOTO_LIB_DIR/history-tracking.sh"
source "$GOTO_LIB_DIR/module.sh" # 新增 - 在依赖模块之后添加
source "$GOTO_LIB_DIR/back-command.sh"
**依赖规则:**
- 无依赖的模块先加载
- 依赖其他模块的模块在依赖模块之后加载
- 主模块goto-function.sh最后加载(依赖所有其他模块)Step 4: Integrate with Main Function
步骤4:与主函数集成
Edit to route commands to your module:
lib/goto-function.shbash
goto() {
case "$1" in
module) # NEW
if command -v goto_module &> /dev/null; then
shift
goto_module "$@"
else
echo "⚠️ Module command not loaded"
fi
return
;;
esac
}编辑,将命令路由到你的模块:
lib/goto-function.shbash
goto() {
case "$1" in
module) # 新增
if command -v goto_module &> /dev/null; then
shift
goto_module "$@"
else
echo "⚠️ 模块命令未加载"
fi
return
;;
esac
}Step 5: Add Tests (100% Coverage Required)
步骤5:添加测试(要求100%覆盖率)
Test File Template:
bash
#!/bin/bash测试文件模板:
bash
#!/bin/bashTest suite for [feature] functionality
[功能]功能测试套件
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/lib/module.sh"
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/lib/module.sh"
Test counters
测试计数器
TESTS_PASSED=0
TESTS_FAILED=0
TESTS_PASSED=0
TESTS_FAILED=0
Test helper
测试辅助函数
pass() {
echo "✓ PASS: $1"
((TESTS_PASSED++))
}
fail() {
echo "✗ FAIL: $1"
((TESTS_FAILED++))
}
pass() {
echo "✓ PASS: $1"
((TESTS_PASSED++))
}
fail() {
echo "✗ FAIL: $1"
((TESTS_FAILED++))
}
Test 1: [Description]
测试1: [描述]
test_feature() {
# Arrange
local input="test"
# Act
local result=$(function_under_test "$input")
# Assert
if [[ "$result" == "expected" ]]; then
pass "Feature works"
else
fail "Feature failed: got '$result'"
fi}
test_feature() {
# 准备
local input="test"
# 执行
local result=$(function_under_test "$input")
# 断言
if [[ "$result" == "expected" ]]; then
pass "功能正常"
else
fail "功能失败: 得到 '$result'"
fi}
Run tests
运行测试
test_feature
test_feature
Summary
总结
echo ""
echo "Tests passed: $TESTS_PASSED"
echo "Tests failed: $TESTS_FAILED"
[ $TESTS_FAILED -eq 0 ] && exit 0 || exit 1
**Test Categories (ALL Required):**
1. **Unit Tests** - Test individual functions
2. **Integration Tests** - Test module interaction
3. **Edge Cases** - Test boundary conditions
4. **Performance Tests** - Validate speed requirements
**Example from CET-77 (Recent Directories):**
```bashecho ""
echo "通过测试数: $TESTS_PASSED"
echo "失败测试数: $TESTS_FAILED"
[ $TESTS_FAILED -eq 0 ] && exit 0 || exit 1
**测试类别(全部要求覆盖):**
1. **单元测试** - 测试单个函数
2. **集成测试** - 测试模块交互
3. **边界情况** - 测试边界条件
4. **性能测试** - 验证速度要求
**CET-77(最近访问目录)示例:**
```bashUnit test
单元测试
test_get_recent_dirs() {
result=$(__goto_recent_dirs 5)
[ $? -eq 0 ] && pass "Get recent dirs" || fail "Get recent dirs failed"
}
test_get_recent_dirs() {
result=$(__goto_recent_dirs 5)
[ $? -eq 0 ] && pass "获取最近访问目录" || fail "获取最近访问目录失败"
}
Integration test
集成测试
test_goto_recent_navigation() {
goto recent 1
[ $? -eq 0 ] && pass "Navigate to recent dir" || fail "Navigation failed"
}
test_goto_recent_navigation() {
goto recent 1
[ $? -eq 0 ] && pass "导航到最近访问目录" || fail "导航失败"
}
Edge case
边界情况
test_empty_history() {
rm -f ~/.goto_history
result=$(goto recent)
[[ "$result" == "No history" ]] && pass "Empty history" || fail "Empty history check"
}
test_empty_history() {
rm -f ~/.goto_history
result=$(goto recent)
[[ "$result" == "无历史记录" ]] && pass "空历史记录处理" || fail "空历史记录检查失败"
}
Performance test
性能测试
test_recent_speed() {
start=$(date +%s%N)
__goto_recent_dirs 10
end=$(date +%s%N)
duration=$(((end - start) / 1000000))
[ $duration -lt 10 ] && pass "Recent dirs <10ms" || fail "Too slow: ${duration}ms"
}
undefinedtest_recent_speed() {
start=$(date +%s%N)
__goto_recent_dirs 10
end=$(date +%s%N)
duration=$(((end - start) / 1000000))
[ $duration -lt 10 ] && pass "最近访问目录检索<10ms" || fail "速度过慢: ${duration}ms"
}
undefinedStep 6: Document API
步骤6:编写API文档
Add to :
docs/API.mdmarkdown
undefined添加到:
docs/API.mdmarkdown
undefinedModule API
模块API
goto module
goto modulegoto module
goto module[Description of what the module does]
Signature:
bash
goto module <subcommand>Subcommands:
- - [Description]
list - - [Description]
add
Performance: [Target metrics]
Examples:
bash
goto module list
goto module add valueReturn Codes:
- 0 - Success
- 1 - Error
Implementation:
lib/module.sh
**Example from CET-77:**
```markdown[模块功能描述]
签名:
bash
goto module <subcommand>子命令:
- - [描述]
list - - [描述]
add
性能: [目标指标]
示例:
bash
goto module list
goto module add value返回码:
- 0 - 成功
- 1 - 错误
实现文件:
lib/module.sh
**CET-77示例:**
```markdownRecent Directories
最近访问目录
goto recent [n]
goto recent [n]goto recent [n]
goto recent [n]Display recently navigated directories in reverse chronological order.
Signature:
bash
goto recent [n]Parameters:
- - Optional number of recent directories to display (default: all)
n
Performance: <10ms for history retrieval
Examples:
bash
goto recent # Show all recent directories
goto recent 5 # Show 5 most recentImplementation:
lib/recent-command.shundefined按逆时间顺序显示最近导航过的目录。
签名:
bash
goto recent [n]参数:
- - 可选参数,指定显示的最近目录数量(默认:全部)
n
性能: 历史记录检索耗时<10ms
示例:
bash
goto recent # 显示所有最近访问的目录
goto recent 5 # 显示最近5个目录实现文件:
lib/recent-command.shundefinedStep 7: Update User Documentation
步骤7:更新用户文档
Add to :
README.mdmarkdown
undefined添加到:
README.mdmarkdown
undefinedModule
模块
[User-facing description]
bash
goto module list # [Description]
goto module add # [Description]undefined[面向用户的描述]
bash
goto module list # [描述]
goto module add # [描述]undefinedStep 8: Performance Validation
步骤8:性能验证
Validate performance meets targets:
bash
undefined验证性能是否达标:
bash
undefinedAdd benchmark if performance-critical
如果是性能关键功能,添加基准测试
goto benchmark module 10
goto benchmark module 10
Measure overhead
测量开销
time goto_module list
time goto_module list
Expected: <100ms for navigation, <10ms for lookups
预期:导航耗时<100ms,检索耗时<10ms
**Performance Targets:**
- Cached navigation: <100ms
- Bookmark lookup: <10ms
- Cache speedup: >20x
- Cache hit rate: >90%
- Cache build: <5s
**性能目标:**
- 缓存导航:<100ms
- 书签检索:<10ms
- 缓存加速比:>20x
- 缓存命中率:>90%
- 缓存构建:<5sStep 9: Linear Issue Update & Commit
步骤9:更新Linear问题并提交代码
Update Linear Issue:
- Add implementation comment
- Include test results
- Include performance metrics
- Link to commit
- Move to "Complete"
Commit Format:
bash
git commit -m "feat: implement module feature (CET-XX)
[Detailed explanation]
Features:
- Feature 1
- Feature 2
Performance:
- Metric: value
Tests:
- X/X tests passing
- 100% coverage
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>"Commit Types:
- - New feature
feat: - - Bug fix
fix: - - Performance improvement
perf: - - Code refactoring
refactor: - - Add or update tests
test: - - Documentation only
docs: - - Build, dependencies, or tooling
chore:
Example Commit from CET-85:
feat: implement comprehensive benchmark suite (CET-85)
Implement complete benchmark framework with 5 benchmark tests, helpers,
workspace generation, and CSV results storage.
Features:
- 5 benchmark tests: cached vs uncached, multi-level paths, max depth,
cache build performance, parallel navigation
- Benchmark helpers library with timing, stats, workspace management
- CSV results storage in ~/.goto_benchmarks/
- Performance target assertions (<100ms navigation)
- Comprehensive statistical analysis (min/max/mean/median/stddev)
Performance:
- Cached navigation: 26ms (target: <100ms) ✓
- Cache build: 3-5s (target: <5s) ✓
- Speedup ratio: 8x (target: >20x, in progress)
Tests:
- 5/5 benchmark tests passing
- All performance targets met for Phase 1
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>更新Linear问题:
- 添加实现说明
- 包含测试结果
- 包含性能指标
- 关联提交记录
- 移动到“完成”状态
提交格式:
bash
git commit -m "feat: implement module feature (CET-XX)
[详细说明]
Features:
- 功能1
- 功能2
Performance:
- 指标: 值
Tests:
- X/X测试通过
- 100%覆盖率
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>"提交类型:
- - 新功能
feat: - - 修复bug
fix: - - 性能优化
perf: - - 代码重构
refactor: - - 添加或更新测试
test: - - 仅更新文档
docs: - - 构建、依赖或工具相关变更
chore:
CET-85示例提交:
feat: implement comprehensive benchmark suite (CET-85)
Implement complete benchmark framework with 5 benchmark tests, helpers,
workspace generation, and CSV results storage.
Features:
- 5 benchmark tests: cached vs uncached, multi-level paths, max depth,
cache build performance, parallel navigation
- Benchmark helpers library with timing, stats, workspace management
- CSV results storage in ~/.goto_benchmarks/
- Performance target assertions (<100ms navigation)
- Comprehensive statistical analysis (min/max/mean/median/stddev)
Performance:
- Cached navigation: 26ms (target: <100ms) ✓
- Cache build: 3-5s (target: <5s) ✓
- Speedup ratio: 8x (target: >20x, in progress)
Tests:
- 5/5 benchmark tests passing
- All performance targets met for Phase 1
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>Feature Checklist
功能检查清单
Before submitting ANY feature:
- Implementation complete
- Loaded in
goto.sh - Integrated with main function
goto - Tests written and passing (100% coverage)
- API documented in
docs/API.md - User documentation updated in
README.md - Performance validated (if applicable)
- Linear issue updated with results
- Committed with proper message format
在提交任何功能之前,请确认:
- 实现完成
- 已添加到加载序列
goto.sh - 已与主函数集成
goto - 已编写测试并通过(100%覆盖率)
- 已在中编写API文档
docs/API.md - 已更新中的用户文档
README.md - 已验证性能(如适用)
- 已更新Linear问题并添加结果
- 已按正确格式提交代码
Cache System Architecture
缓存系统架构
Purpose: O(1) folder lookup with automatic refresh
Implementation:
lib/cache-index.shKey Components:
- - O(n) index building
__goto_cache_build - - O(1) hash table lookup
__goto_cache_lookup - - TTL-based validation
__goto_cache_is_valid - Auto-refresh on stale cache (24-hour TTL)
Cache File Format:
undefined用途: O(1)时间复杂度的文件夹检索,支持自动刷新
实现文件:
lib/cache-index.sh核心组件:
- - O(n)时间复杂度的索引构建
__goto_cache_build - - O(1)时间复杂度的哈希表检索
__goto_cache_lookup - - 基于TTL的有效性验证
__goto_cache_is_valid - 缓存过期自动刷新(TTL为24小时)
缓存文件格式:
undefinedunix-goto folder index cache
unix-goto folder index cache
Version: 1.0
Version: 1.0
Built: 1697558122
Built: 1697558122
Depth: 3
Depth: 3
Format: folder_name|full_path|depth|last_modified
Format: folder_name|full_path|depth|last_modified
#---
unix-goto|/Users/manu/Documents/LUXOR/Git_Repos/unix-goto|8|1697558100
GAI-3101|/Users/manu/Documents/LUXOR/PROJECTS/GAI-3101|6|1697558050
**Performance:**
- Build time: O(n) - 3-5s for 1200+ folders
- Lookup time: O(1) - <100ms target, 26ms actual
- Storage: ~42KB for 487 folders
**Cache Lookup Return Codes:**
```bash
__goto_cache_lookup "folder"#---
unix-goto|/Users/manu/Documents/LUXOR/Git_Repos/unix-goto|8|1697558100
GAI-3101|/Users/manu/Documents/LUXOR/PROJECTS/GAI-3101|6|1697558050
**性能:**
- 构建时间:O(n) - 1200+个文件夹耗时3-5s
- 检索时间:O(1) - 目标<100ms,实际26ms
- 存储大小:487个文件夹约占42KB
**缓存检索返回码:**
```bash
__goto_cache_lookup "folder"Returns:
返回:
0 - Single match found (path to stdout)
0 - 找到单个匹配项(路径输出到标准输出)
1 - Not found in cache
1 - 缓存中未找到
2 - Multiple matches found (all paths to stdout)
2 - 找到多个匹配项(所有路径输出到标准输出)
undefinedundefinedNavigation Data Flow
导航数据流
User Input → goto "project"
│
├─► Check special cases (list, index, benchmark, @bookmark)
├─► Check multi-level paths (contains /)
├─► Try cache lookup (O(1)) → Cache hit → Navigate
├─► Try direct folder match in search paths
├─► Recursive search (max depth 3)
│ ├─► Single match → Navigate
│ └─► Multiple matches → Show disambiguation
└─► Natural language AI resolution (if spaces)用户输入 → goto "project"
│
├─► 检查特殊情况(list, index, benchmark, @bookmark)
├─► 检查多级路径(包含/)
├─► 尝试缓存检索(O(1))→ 缓存命中 → 导航
├─► 尝试在搜索路径中直接匹配文件夹
├─► 递归搜索(最大深度3)
│ ├─► 单个匹配 → 导航
│ └─► 多个匹配 → 显示歧义消除选项
└─► 自然语言AI解析(如果包含空格)Bookmark System Architecture
书签系统架构
Storage:
~/.goto_bookmarksFormat:
work|/Users/manu/work|1697558122
api|/Users/manu/code/api-server|1697558130Key Functions:
- - Add with validation
__goto_bookmark_add - - Remove by name
__goto_bookmark_remove - - Retrieve path (O(1) grep)
__goto_bookmark_get - - Navigate to bookmark
__goto_bookmark_goto
Performance Target: <10ms lookup time
Usage:
bash
bookmark add work /path/to/work
bookmark remove work
goto @work存储位置:
~/.goto_bookmarks格式:
work|/Users/manu/work|1697558122
api|/Users/manu/code/api-server|1697558130核心函数:
- - 添加书签并验证
__goto_bookmark_add - - 按名称删除书签
__goto_bookmark_remove - - 检索路径(O(1)时间复杂度的grep操作)
__goto_bookmark_get - - 导航到书签
__goto_bookmark_goto
性能目标: 检索耗时<10ms
用法:
bash
bookmark add work /path/to/work
bookmark remove work
goto @workHistory Tracking Architecture
历史记录跟踪架构
Storage:
~/.goto_historyFormat:
1697558122|/Users/manu/work
1697558130|/Users/manu/Documents/LUXORKey Functions:
- - Append with auto-trim (max 100 entries)
__goto_track - - Retrieve full history
__goto_get_history - - Get unique directories in reverse chronological order
__goto_recent_dirs - - Stack-based back navigation
__goto_stack_push/pop
Example Usage:
bash
goto recent # Show all recent directories
goto recent 5 # Show 5 most recent
back # Go back to previous directory存储位置:
~/.goto_history格式:
1697558122|/Users/manu/work
1697558130|/Users/manu/Documents/LUXOR核心函数:
- - 追加记录并自动修剪(最多100条)
__goto_track - - 检索完整历史记录
__goto_get_history - - 获取按逆时间顺序排列的唯一目录
__goto_recent_dirs - - 基于栈的返回导航
__goto_stack_push/pop
示例用法:
bash
goto recent # 显示所有最近访问的目录
goto recent 5 # 显示最近5个目录
back # 返回上一个目录Examples
示例
Example 1: Adding a Recent Directories Feature (CET-77)
示例1:添加最近访问目录功能(CET-77)
Step 1: Plan
Feature: Recent Directories Command
Problem: Users can't quickly revisit recently navigated directories
Interface: goto recent [n]
Performance: <10ms for history retrieval
Dependencies: history-tracking.sh
Tests: List recent, empty history, limit entries, navigate by number
Docs: API.md, README.mdStep 2: Create Module ()
lib/recent-command.shbash
#!/bin/bash步骤1:规划
Feature: 最近访问目录命令
Problem: 用户无法快速重新访问最近导航过的目录
Interface: goto recent [n]
Performance: 历史记录检索耗时<10ms
Dependencies: history-tracking.sh
Tests: 列出最近目录、空历史记录、限制条目数、按编号导航
Docs: API.md, README.md步骤2:创建模块 ()
lib/recent-command.shbash
#!/bin/bashunix-goto - Recent directories command
unix-goto - 最近访问目录命令
Get recent directories
获取最近访问的目录
__goto_recent_dirs() {
local limit="${1:-}"
if [ ! -f "$GOTO_HISTORY_FILE" ]; then
return 1
fi
# Extract paths, reverse order, unique, limit
local dirs=$(awk -F'|' '{print $2}' "$GOTO_HISTORY_FILE" | \
tac | \
awk '!seen[$0]++' | \
${limit:+head -n "$limit"})
echo "$dirs"
return 0}
__goto_recent_dirs() {
local limit="${1:-}"
if [ ! -f "$GOTO_HISTORY_FILE" ]; then
return 1
fi
# 提取路径、逆序、去重、限制数量
local dirs=$(awk -F'|' '{print $2}' "$GOTO_HISTORY_FILE" | \
tac | \
awk '!seen[$0]++' | \
${limit:+head -n "$limit"})
echo "$dirs"
return 0}
Recent command implementation
最近访问目录命令实现
goto_recent() {
local limit="${1:-}"
local dirs=$(__goto_recent_dirs "$limit")
if [ -z "$dirs" ]; then
echo "No recent directories"
return 1
fi
echo "$dirs"
return 0}
**Step 3: Add to Loader** (`goto.sh`)
```bash
source "$GOTO_LIB_DIR/history-tracking.sh"
source "$GOTO_LIB_DIR/recent-command.sh" # NEWStep 4: Integrate ()
lib/goto-function.shbash
goto() {
case "$1" in
recent)
shift
goto_recent "$@"
return
;;
esac
}Step 5: Add Tests ()
test-recent.shbash
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/lib/recent-command.sh"
TESTS_PASSED=0
TESTS_FAILED=0
pass() { echo "✓ PASS: $1"; ((TESTS_PASSED++)); }
fail() { echo "✗ FAIL: $1"; ((TESTS_FAILED++)); }goto_recent() {
local limit="${1:-}"
local dirs=$(__goto_recent_dirs "$limit")
if [ -z "$dirs" ]; then
echo "无最近访问的目录"
return 1
fi
echo "$dirs"
return 0}
**步骤3:添加到加载器** (`goto.sh`)
```bash
source "$GOTO_LIB_DIR/history-tracking.sh"
source "$GOTO_LIB_DIR/recent-command.sh" # 新增步骤4:集成到主函数 ()
lib/goto-function.shbash
goto() {
case "$1" in
recent)
shift
goto_recent "$@"
return
;;
esac
}步骤5:添加测试 ()
test-recent.shbash
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/lib/recent-command.sh"
TESTS_PASSED=0
TESTS_FAILED=0
pass() { echo "✓ PASS: $1"; ((TESTS_PASSED++)); }
fail() { echo "✗ FAIL: $1"; ((TESTS_FAILED++)); }Test 1: Get recent directories
测试1: 获取最近访问目录
test_get_recent() {
result=$(__goto_recent_dirs)
[ $? -eq 0 ] && pass "Get recent dirs" || fail "Failed"
}
test_get_recent() {
result=$(__goto_recent_dirs)
[ $? -eq 0 ] && pass "获取最近目录成功" || fail "获取最近目录失败"
}
Test 2: Empty history
测试2: 空历史记录
test_empty_history() {
rm -f ~/.goto_history
result=$(goto_recent)
[[ "$result" == "No recent" ]] && pass "Empty history" || fail "Empty check"
}
test_empty_history() {
rm -f ~/.goto_history
result=$(goto_recent)
[[ "$result" == "无最近访问目录" ]] && pass "空历史记录处理正常" || fail "空历史记录检查失败"
}
Test 3: Limit results
测试3: 限制结果数量
test_limit_results() {
result=$(__goto_recent_dirs 5)
count=$(echo "$result" | wc -l)
[ $count -le 5 ] && pass "Limit to 5" || fail "Limit failed"
}
test_limit_results() {
result=$(__goto_recent_dirs 5)
count=$(echo "$result" | wc -l)
[ $count -le 5 ] && pass "限制显示5条记录正常" || fail "限制数量失败"
}
Run tests
运行测试
test_get_recent
test_empty_history
test_limit_results
echo ""
echo "Passed: $TESTS_PASSED, Failed: $TESTS_FAILED"
[ $TESTS_FAILED -eq 0 ] && exit 0 || exit 1
**Step 6: Document API** (`docs/API.md`)
```markdowntest_get_recent
test_empty_history
test_limit_results
echo ""
echo "通过测试数: $TESTS_PASSED, 失败测试数: $TESTS_FAILED"
[ $TESTS_FAILED -eq 0 ] && exit 0 || exit 1
**步骤6:编写API文档** (`docs/API.md`)
```markdownRecent Directories
最近访问目录
goto recent [n]
goto recent [n]goto recent [n]
goto recent [n]Display recently navigated directories in reverse chronological order.
Performance: <10ms for history retrieval
Examples:
bash
goto recent # Show all recent directories
goto recent 5 # Show 5 most recent
**Step 7: Update README** (`README.md`)
```markdown按逆时间顺序显示最近导航过的目录。
性能: 历史记录检索耗时<10ms
示例:
bash
goto recent # 显示所有最近访问的目录
goto recent 5 # 显示最近5个目录
**步骤7:更新README** (`README.md`)
```markdownRecent Directories
最近访问目录
Quickly revisit recently navigated directories:
bash
goto recent # Show all recent directories
goto recent 5 # Show 5 most recent
**Step 8: Validate Performance**
```bash
time goto recent快速重新访问最近导航过的目录:
bash
goto recent # 显示所有最近访问的目录
goto recent 5 # 显示最近5个目录
**步骤8:验证性能**
```bash
time goto recentExpected: <10ms
预期: <10ms
**Step 9: Commit**
```bash
git commit -m "feat: implement recent directories command (CET-77)
Add goto recent command to display recently navigated directories.
Features:
- List all recent directories
- Limit to N most recent
- Unique directories only
- Reverse chronological order
Performance:
- History retrieval: <10ms ✓
Tests:
- 3/3 tests passing
- 100% coverage
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>"
**步骤9:提交代码**
```bash
git commit -m "feat: implement recent directories command (CET-77)
添加goto recent命令以显示最近导航过的目录。
Features:
- 列出所有最近访问的目录
- 限制显示N个最近目录
- 仅显示唯一目录
- 按逆时间顺序排列
Performance:
- 历史记录检索: <10ms ✓
Tests:
- 3/3测试通过
- 100%覆盖率
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>"Example 2: Adding Benchmark Suite (CET-85)
示例2:添加基准测试套件(CET-85)
Complete benchmark implementation with helpers, workspace, and CSV storage.
Benchmark Structure ()
benchmarks/bench-cached-vs-uncached.shbash
#!/bin/bash完整的基准测试实现,包含辅助函数、测试工作区和CSV存储。
基准测试结构 ()
benchmarks/bench-cached-vs-uncached.shbash
#!/bin/bashBenchmark: Cached vs Uncached Navigation Performance
Benchmark: Cached vs Uncached Navigation Performance
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$SCRIPT_DIR/.."
source "$SCRIPT_DIR/bench-helpers.sh"
source "$REPO_DIR/lib/cache-index.sh"
main() {
bench_header "Cached vs Uncached Navigation Performance"
echo "Configuration:"
echo " Iterations: 10"
echo " Warmup: 3 runs"
echo ""
benchmark_cached_vs_uncached
generate_summary}
benchmark_cached_vs_uncached() {
bench_section "Benchmark: Cached vs Uncached Lookup"
# Setup workspace
local workspace=$(bench_create_workspace "medium")
# Phase 1: Uncached lookup
echo "Phase 1: Uncached lookup (no cache)"
echo "─────────────────────────────────"
# Warmup
bench_warmup "__goto_cache_lookup unix-goto" 3
# Run benchmark
local uncached_stats=$(bench_run "uncached" \
"__goto_cache_lookup unix-goto" 10)
IFS=',' read -r uc_min uc_max uc_mean uc_median uc_stddev <<< "$uncached_stats"
bench_print_stats "$uncached_stats" "Uncached Results"
# Phase 2: Cached lookup
echo ""
echo "Phase 2: Cached lookup (with cache)"
echo "─────────────────────────────────"
# Build cache
__goto_cache_build
# Warmup
bench_warmup "__goto_cache_lookup unix-goto" 3
# Run benchmark
local cached_stats=$(bench_run "cached" \
"__goto_cache_lookup unix-goto" 10)
IFS=',' read -r c_min c_max c_mean c_median c_stddev <<< "$cached_stats"
bench_print_stats "$cached_stats" "Cached Results"
# Calculate speedup
local speedup=$(bench_compare "$uc_mean" "$c_mean")
echo ""
echo "Speedup Analysis:"
echo " Speedup ratio: ${speedup}x"
# Assert targets
bench_assert_target "$c_mean" 100 "Cached navigation time"
# Save results
bench_save_result "cached_vs_uncached" "$uncached_stats" "uncached"
bench_save_result "cached_vs_uncached" "$cached_stats" "cached"
# Cleanup
bench_cleanup_workspace "$workspace"}
main
exit 0
**Benchmark Helpers** (`benchmarks/bench-helpers.sh`)
```bash
#!/bin/bashSCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$SCRIPT_DIR/.."
source "$SCRIPT_DIR/bench-helpers.sh"
source "$REPO_DIR/lib/cache-index.sh"
main() {
bench_header "Cached vs Uncached Navigation Performance"
echo "Configuration:"
echo " Iterations: 10"
echo " Warmup: 3 runs"
echo ""
benchmark_cached_vs_uncached
generate_summary}
benchmark_cached_vs_uncached() {
bench_section "Benchmark: Cached vs Uncached Lookup"
# 创建测试工作区
local workspace=$(bench_create_workspace "medium")
# 阶段1: 无缓存检索
echo "Phase 1: Uncached lookup (no cache)"
echo "─────────────────────────────────"
# 预热
bench_warmup "__goto_cache_lookup unix-goto" 3
# 运行基准测试
local uncached_stats=$(bench_run "uncached" \
"__goto_cache_lookup unix-goto" 10)
IFS=',' read -r uc_min uc_max uc_mean uc_median uc_stddev <<< "$uncached_stats"
bench_print_stats "$uncached_stats" "Uncached Results"
# 阶段2: 有缓存检索
echo ""
echo "Phase 2: Cached lookup (with cache)"
echo "─────────────────────────────────"
# 构建缓存
__goto_cache_build
# 预热
bench_warmup "__goto_cache_lookup unix-goto" 3
# 运行基准测试
local cached_stats=$(bench_run "cached" \
"__goto_cache_lookup unix-goto" 10)
IFS=',' read -r c_min c_max c_mean c_median c_stddev <<< "$cached_stats"
bench_print_stats "$cached_stats" "Cached Results"
# 计算加速比
local speedup=$(bench_compare "$uc_mean" "$c_mean")
echo ""
echo "Speedup Analysis:"
echo " Speedup ratio: ${speedup}x"
# 断言目标
bench_assert_target "$c_mean" 100 "Cached navigation time"
# 保存结果
bench_save_result "cached_vs_uncached" "$uncached_stats" "uncached"
bench_save_result "cached_vs_uncached" "$cached_stats" "cached"
# 清理工作区
bench_cleanup_workspace "$workspace"}
main
exit 0
**基准测试辅助函数** (`benchmarks/bench-helpers.sh`)
```bash
#!/bin/bashBenchmark helper functions
Benchmark helper functions
BENCH_RESULTS_DIR="${BENCH_RESULTS_DIR:-$HOME/.goto_benchmarks}"
BENCH_RESULTS_DIR="${BENCH_RESULTS_DIR:-$HOME/.goto_benchmarks}"
High-precision timing
高精度计时
bench_time_ms() {
local cmd="$*"
local start=$(date +%s%N)
eval "$cmd" > /dev/null 2>&1
local end=$(date +%s%N)
echo $(((end - start) / 1000000))
}
bench_time_ms() {
local cmd="$*"
local start=$(date +%s%N)
eval "$cmd" > /dev/null 2>&1
local end=$(date +%s%N)
echo $(((end - start) / 1000000))
}
Calculate statistics
计算统计数据
bench_calculate_stats() {
local values=("$@")
local count=${#values[@]}
# Sort values
IFS=$'\n' sorted=($(sort -n <<<"${values[*]}"))
# Min/Max
local min=${sorted[0]}
local max=${sorted[$((count-1))]}
# Mean
local sum=0
for val in "${values[@]}"; do
sum=$((sum + val))
done
local mean=$((sum / count))
# Median
local mid=$((count / 2))
local median=${sorted[$mid]}
# Standard deviation
local variance=0
for val in "${values[@]}"; do
local diff=$((val - mean))
variance=$((variance + diff * diff))
done
variance=$((variance / count))
local stddev=$(echo "sqrt($variance)" | bc)
echo "$min,$max,$mean,$median,$stddev"}
bench_calculate_stats() {
local values=("$@")
local count=${#values[@]}
# 排序
IFS=$'\n' sorted=($(sort -n <<<"${values[*]}"))
# 最小值/最大值
local min=${sorted[0]}
local max=${sorted[$((count-1))]}
# 平均值
local sum=0
for val in "${values[@]}"; do
sum=$((sum + val))
done
local mean=$((sum / count))
# 中位数
local mid=$((count / 2))
local median=${sorted[$mid]}
# 标准差
local variance=0
for val in "${values[@]}"; do
local diff=$((val - mean))
variance=$((variance + diff * diff))
done
variance=$((variance / count))
local stddev=$(echo "sqrt($variance)" | bc)
echo "$min,$max,$mean,$median,$stddev"}
Print header
打印标题
bench_header() {
local title="$1"
echo "╔══════════════════════════════════════════════════════════════════╗"
printf "║ %-62s ║\n" "$title"
echo "╚══════════════════════════════════════════════════════════════════╝"
echo ""
}
bench_header() {
local title="$1"
echo "╔══════════════════════════════════════════════════════════════════╗"
printf "║ %-62s ║\n" "$title"
echo "╚══════════════════════════════════════════════════════════════════╝"
echo ""
}
Print section
打印章节
bench_section() {
local title="$1"
echo "$title"
echo "─────────────────────────────────────────────────────────────────"
}
bench_section() {
local title="$1"
echo "$title"
echo "─────────────────────────────────────────────────────────────────"
}
Print statistics block
打印统计数据块
bench_print_stats() {
local stats="$1"
local label="$2"
IFS=',' read -r min max mean median stddev <<< "$stats"
echo ""
echo "$label:"
printf " Min: %dms\n" "$min"
printf " Max: %dms\n" "$max"
printf " Mean: %dms\n" "$mean"
printf " Median: %dms\n" "$median"
printf " Std Dev: %.2fms\n" "$stddev"}
bench_print_stats() {
local stats="$1"
local label="$2"
IFS=',' read -r min max mean median stddev <<< "$stats"
echo ""
echo "$label:"
printf " Min: %dms\n" "$min"
printf " Max: %dms\n" "$max"
printf " Mean: %dms\n" "$mean"
printf " Median: %dms\n" "$median"
printf " Std Dev: %.2fms\n" "$stddev"}
Assert performance target
断言性能目标
bench_assert_target() {
local actual="$1"
local target="$2"
local label="$3"
if [ "$actual" -lt "$target" ]; then
echo "✓ $label meets target: ${actual}ms (target: <${target}ms)"
else
echo "✗ $label exceeds target: ${actual}ms (target: <${target}ms)"
fi}
bench_assert_target() {
local actual="$1"
local target="$2"
local label="$3"
if [ "$actual" -lt "$target" ]; then
echo "✓ $label meets target: ${actual}ms (target: <${target}ms)"
else
echo "✗ $label exceeds target: ${actual}ms (target: <${target}ms)"
fi}
Initialize results directory
初始化结果目录
bench_init() {
mkdir -p "$BENCH_RESULTS_DIR"
}
bench_init() {
mkdir -p "$BENCH_RESULTS_DIR"
}
Save benchmark result
保存基准测试结果
bench_save_result() {
bench_init
local name="$1"
local stats="$2"
local metadata="${3:-}"
local timestamp=$(date +%s)
local results_file="$BENCH_RESULTS_DIR/results.csv"
# Create header if file doesn't exist
if [ ! -f "$results_file" ]; then
echo "timestamp,benchmark_name,operation,min_ms,max_ms,mean_ms,median_ms,stddev,metadata" > "$results_file"
fi
# Append result
echo "$timestamp,$name,$metadata,$stats" >> "$results_file"}
bench_save_result() {
bench_init
local name="$1"
local stats="$2"
local metadata="${3:-}"
local timestamp=$(date +%s)
local results_file="$BENCH_RESULTS_DIR/results.csv"
# 如果文件不存在,创建表头
if [ ! -f "$results_file" ]; then
echo "timestamp,benchmark_name,operation,min_ms,max_ms,mean_ms,median_ms,stddev,metadata" > "$results_file"
fi
# 追加结果
echo "$timestamp,$name,$metadata,$stats" >> "$results_file"}
Create test workspace
创建测试工作区
bench_create_workspace() {
local size="${1:-medium}"
local workspace=$(mktemp -d)
case "$size" in
small)
# 10 folders
for i in {1..10}; do
mkdir -p "$workspace/folder-$i"
done
;;
medium)
# 50 folders
for i in {1..50}; do
mkdir -p "$workspace/folder-$i"
done
;;
large)
# 500 folders
for i in {1..500}; do
mkdir -p "$workspace/folder-$i"
done
;;
esac
echo "$workspace"}
bench_create_workspace() {
local size="${1:-medium}"
local workspace=$(mktemp -d)
case "$size" in
small)
# 10个文件夹
for i in {1..10}; do
mkdir -p "$workspace/folder-$i"
done
;;
medium)
# 50个文件夹
for i in {1..50}; do
mkdir -p "$workspace/folder-$i"
done
;;
large)
# 500个文件夹
for i in {1..500}; do
mkdir -p "$workspace/folder-$i"
done
;;
esac
echo "$workspace"}
Cleanup workspace
清理工作区
bench_cleanup_workspace() {
local workspace="$1"
rm -rf "$workspace"
}
bench_cleanup_workspace() {
local workspace="$1"
rm -rf "$workspace"
}
Run benchmark iterations
运行基准测试迭代
bench_run() {
local name="$1"
local cmd="$2"
local iterations="${3:-10}"
local times=()
for i in $(seq 1 $iterations); do
local time=$(bench_time_ms "$cmd")
times+=("$time")
printf " Run %2d: %dms\n" "$i" "$time"
done
bench_calculate_stats "${times[@]}"}
bench_run() {
local name="$1"
local cmd="$2"
local iterations="${3:-10}"
local times=()
for i in $(seq 1 $iterations); do
local time=$(bench_time_ms "$cmd")
times+=("$time")
printf " Run %2d: %dms\n" "$i" "$time"
done
bench_calculate_stats "${times[@]}"}
Warmup iterations
预热迭代
bench_warmup() {
local cmd="$1"
local iterations="${2:-3}"
for i in $(seq 1 $iterations); do
eval "$cmd" > /dev/null 2>&1
done}
bench_warmup() {
local cmd="$1"
local iterations="${2:-3}"
for i in $(seq 1 $iterations); do
eval "$cmd" > /dev/null 2>&1
done}
Compare performance
比较性能
bench_compare() {
local baseline="$1"
local optimized="$2"
local speedup=$(echo "scale=2; $baseline / $optimized" | bc)
echo "$speedup"}
undefinedbench_compare() {
local baseline="$1"
local optimized="$2"
local speedup=$(echo "scale=2; $baseline / $optimized" | bc)
echo "$speedup"}
undefinedBest Practices
最佳实践
Code Style Standards
代码风格标准
Function Structure:
bash
function_name() {
local param1="$1"
local param2="${2:-default}"
# Validate inputs
if [ -z "$param1" ]; then
echo "Error: param1 required"
return 1
fi
# Main logic
local result=$(process "$param1")
# Return value
echo "$result"
return 0
}Error Handling:
bash
undefined函数结构:
bash
function_name() {
local param1="$1"
local param2="${2:-default}"
# 验证输入
if [ -z "$param1" ]; then
echo "错误: 需要param1"
return 1
fi
# 主逻辑
local result=$(process "$param1")
# 返回值
echo "$result"
return 0
}错误处理:
bash
undefinedAlways check command success
始终检查命令执行结果
if ! goto index rebuild; then
echo "Failed to rebuild cache"
return 1
fi
if ! goto index rebuild; then
echo "缓存重建失败"
return 1
fi
Use meaningful error messages
使用有意义的错误消息
if [ ! -d "$target_dir" ]; then
echo "❌ Directory not found: $target_dir"
return 1
fi
**Comments:**
```bashif [ ! -d "$target_dir" ]; then
echo "❌ 目录不存在: $target_dir"
return 1
fi
**注释:**
```bashGood: Explain why, not what
好的注释: 解释原因,而非内容
Cache lookup is O(1) because we use grep on indexed file
缓存检索是O(1)时间复杂度,因为我们使用grep检索索引文件
Bad: Explain what (obvious from code)
不好的注释: 解释内容(代码本身已明确)
Set folder_name to first parameter
将folder_name设为第一个参数
folder_name="$1"
undefinedfolder_name="$1"
undefinedData File Format Pattern
数据文件格式模式
Standard format: Pipe-delimited with metadata header
bash
undefined标准格式: 管道分隔,带元数据头
bash
undefinedModule data file
模块数据文件
Version: 1.0
Version: 1.0
Built: [timestamp]
Built: [时间戳]
Format: field1|field2|field3
Format: field1|field2|field3
#---
value1|value2|value3
value1|value2|value3
undefined#---
value1|value2|value3
value1|value2|value3
undefinedPerformance Optimization Tips
性能优化技巧
Cache System:
- Use cache for all lookups
- Limit recursive search depth
- Avoid redundant filesystem operations
- Use for fast text matching
grep
Memory:
- Cache file: <100KB for 500 folders
- Memory usage: Minimal (shell functions only)
- No persistent processes
缓存系统:
- 所有检索都使用缓存
- 限制递归搜索深度
- 避免冗余的文件系统操作
- 使用进行快速文本匹配
grep
内存:
- 缓存文件: 500个文件夹占<100KB
- 内存使用: 极小(仅shell函数)
- 无持久化进程
Debugging Tips
调试技巧
Enable Bash Tracing:
bash
set -x
source goto.sh
goto test
set +xCheck Function Existence:
bash
if declare -f __goto_cache_lookup > /dev/null; then
echo "Function loaded"
fiDebug Cache Issues:
bash
undefined启用Bash跟踪:
bash
set -x
source goto.sh
goto test
set +x检查函数是否存在:
bash
if declare -f __goto_cache_lookup > /dev/null; then
echo "函数已加载"
fi调试缓存问题:
bash
undefinedView cache file
查看缓存文件
cat ~/.goto_index
cat ~/.goto_index
Check cache age
检查缓存年龄
stat -f %m ~/.goto_index
stat -f %m ~/.goto_index
Rebuild and observe
重建缓存并观察
goto index rebuild
undefinedgoto index rebuild
undefinedLinear Workflow Integration
Linear工作流集成
Linear Project Details:
- Team: Ceti-luxor
- Project: unix-goto - Shell Navigation Tool
- Project ID: 7232cafe-cb71-4310-856a-0d584e6f3df0
Issue Lifecycle:
Backlog → In Progress → CompleteStandard Workflow:
- Pick an issue from Phase 3 backlog
- Move to "In Progress" in Linear
- Create feature branch:
feature/CET-XX-feature-name - Implement following 9-step workflow
- Test thoroughly (100% coverage)
- Commit with proper format
- Update Linear issue with results
- Move to "Complete"
Linear Issue Template:
markdown
undefinedLinear项目详情:
- Team: Ceti-luxor
- Project: unix-goto - Shell Navigation Tool
- Project ID: 7232cafe-cb71-4310-856a-0d584e6f3df0
问题生命周期:
Backlog → In Progress → Complete标准工作流:
- 从Phase 3待办事项中选择一个问题
- 在Linear中将其移动到“In Progress”状态
- 创建功能分支:
feature/CET-XX-feature-name - 按照9步流程实现功能
- 全面测试(100%覆盖率)
- 按正确格式提交代码
- 在Linear问题中更新结果
- 移动到“Complete”状态
Linear问题模板:
markdown
undefinedProblem
问题
What problem does this solve?
该功能解决什么问题?
Solution
解决方案
How will we solve it?
我们将如何解决?
Acceptance Criteria
验收标准
- Criterion 1
- Criterion 2
- Tests pass
- Performance targets met
- 标准1
- 标准2
- 测试通过
- 性能目标达标
Performance Targets
性能目标
- Metric 1: <target>
- Metric 2: <target>
- 指标1: <目标值>
- 指标2: <目标值>
Dependencies
依赖
- Issue CET-XX (if applicable)
undefined- 问题CET-XX(如适用)
undefinedQuick Reference
快速参考
Essential Commands
核心命令
bash
undefinedbash
undefinedDevelopment
开发
source goto.sh # Load all modules
goto index rebuild # Rebuild cache
bash test-cache.sh # Run cache tests
bash test-benchmark.sh # Run benchmark tests
goto benchmark all # Run all benchmarks
source goto.sh # 加载所有模块
goto index rebuild # 重建缓存
bash test-cache.sh # 运行缓存测试
bash test-benchmark.sh # 运行基准测试
goto benchmark all # 运行所有基准测试
Debugging
调试
set -x; goto project; set +x # Trace execution
declare -F | grep goto # List functions
cat ~/.goto_index # View cache
set -x; goto project; set +x # 跟踪执行过程
declare -F | grep goto # 列出所有函数
cat ~/.goto_index # 查看缓存
Git workflow
Git工作流
git checkout -b feature/CET-XX # Create branch
git commit -m "feat: ..." # Commit with proper format
git push origin feature/CET-XX # Push to remote
git checkout -b feature/CET-XX # 创建分支
git commit -m "feat: ..." # 按正确格式提交
git push origin feature/CET-XX # 推送到远程仓库
Performance
性能
time goto project # Measure navigation
goto benchmark navigation # Benchmark navigation
goto index status # Check cache health
undefinedtime goto project # 测量导航耗时
goto benchmark navigation # 基准测试导航性能
goto index status # 检查缓存健康状态
undefinedFile Locations
文件位置
~/.goto_index - Cache file
~/.goto_bookmarks - Bookmarks file
~/.goto_history - History file
~/.goto_stack - Navigation stack
~/.goto_benchmarks/ - Benchmark results directory~/.goto_index - 缓存文件
~/.goto_bookmarks - 书签文件
~/.goto_history - 历史记录文件
~/.goto_stack - 导航栈文件
~/.goto_benchmarks/ - 基准测试结果目录Performance Targets Summary
性能目标汇总
| Metric | Target | Current |
|---|---|---|
| Cached navigation | <100ms | 26ms ✓ |
| Cache build | <5s | 3-5s ✓ |
| Cache hit rate | >90% | 92-95% ✓ |
| Speedup ratio | 20-50x | 8x ⚠ |
| Test coverage | 100% | 100% ✓ |
Skill Version: 1.0
Last Updated: October 2025
Maintained By: Manu Tej + Claude Code
Source Repository: https://github.com/manutej/unix-goto
| 指标 | 目标 | 当前值 |
|---|---|---|
| 缓存导航耗时 | <100ms | 26ms ✓ |
| 缓存构建时间 | <5s | 3-5s ✓ |
| 缓存命中率 | >90% | 92-95% ✓ |
| 加速比 | 20-50x | 8x ⚠ |
| 测试覆盖率 | 100% | 100% ✓ |
技能版本: 1.0
最后更新: 2025年10月
维护者: Manu Tej + Claude Code
源码仓库: https://github.com/manutej/unix-goto