mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-23 02:35:38 +01:00
feat(claudecode): add usage examples and test script for ClaudeCode plugin
- Introduced a new examples.zsh file demonstrating various usage scenarios for the ClaudeCode Oh My Zsh plugin, including basic commands, model selection, Git integration, and advanced workflows. - Added a test_plugin.zsh script to validate the functionality of the plugin, including alias and function definitions, as well as specific command tests. - Enhanced the testing framework to ensure robust functionality and user experience.
This commit is contained in:
parent
4830a615a2
commit
f02139ac12
2 changed files with 337 additions and 0 deletions
128
plugins/claudecode/examples.zsh
Normal file
128
plugins/claudecode/examples.zsh
Normal file
|
|
@ -0,0 +1,128 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
# ClaudeCode Plugin Usage Examples
|
||||||
|
# This file demonstrates various ways to use the ClaudeCode Oh My Zsh plugin
|
||||||
|
|
||||||
|
echo "🚀 ClaudeCode Plugin Usage Examples"
|
||||||
|
echo "===================================="
|
||||||
|
|
||||||
|
# Basic usage examples
|
||||||
|
echo "📝 Basic Usage:"
|
||||||
|
echo " cc # Start interactive Claude session"
|
||||||
|
echo " ccp 'explain this function' # Quick print mode"
|
||||||
|
echo " ccc # Continue last conversation"
|
||||||
|
echo " ccr abc123 # Resume specific session"
|
||||||
|
echo " ccv 'debug this with verbose output' # Verbose mode"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Model selection examples
|
||||||
|
echo "🤖 Model Selection:"
|
||||||
|
echo " ccsonnet 'use Sonnet model' # Use Claude Sonnet"
|
||||||
|
echo " ccopus 'use Opus model' # Use Claude Opus"
|
||||||
|
echo " cchaiku 'use Haiku model' # Use Claude Haiku"
|
||||||
|
echo " cc --model claude-3-5-sonnet-20241022 'specific model version'"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Git integration examples
|
||||||
|
echo "🔧 Git Integration:"
|
||||||
|
echo " claude-git commit # AI-assisted commit"
|
||||||
|
echo " claude-git pr 'bug fix description' # Create PR description"
|
||||||
|
echo " claude-git diff HEAD~1 # Explain git diff"
|
||||||
|
echo " claude-git log --author='john' # Summarize commits"
|
||||||
|
echo " claude-git conflicts # Help resolve conflicts"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Quick patterns examples
|
||||||
|
echo "⚡ Quick Patterns:"
|
||||||
|
echo " claude-quick explain 'async/await' # Explain concepts"
|
||||||
|
echo " claude-quick debug 'error message' # Debug issues"
|
||||||
|
echo " claude-quick review 'code snippet' # Code review"
|
||||||
|
echo " claude-quick fix 'bug description' # Fix problems"
|
||||||
|
echo " claude-quick optimize 'slow query' # Optimize code"
|
||||||
|
echo " claude-quick refactor 'legacy code' # Refactor code"
|
||||||
|
echo " claude-quick test 'new feature' # Write tests"
|
||||||
|
echo " claude-quick docs 'API endpoint' # Write docs"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Pipe examples
|
||||||
|
echo "🔄 Pipe Operations:"
|
||||||
|
echo " cat app.js | claude-pipe 'explain this code'"
|
||||||
|
echo " git log --oneline | claude-pipe 'summarize commits'"
|
||||||
|
echo " npm test 2>&1 | claude-pipe 'fix failing tests'"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Enhanced pipe examples
|
||||||
|
echo "🔄 Enhanced Pipe Operations:"
|
||||||
|
echo " cat app.js | claude-pipe-enhanced code 'find bugs'"
|
||||||
|
echo " tail -f error.log | claude-pipe-enhanced log 'analyze errors'"
|
||||||
|
echo " npm test 2>&1 | claude-pipe-enhanced error 'fix tests'"
|
||||||
|
echo " curl api/data | claude-pipe-enhanced json 'summarize data'"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Project analysis examples
|
||||||
|
echo "📊 Project Analysis:"
|
||||||
|
echo " claude-project analyze # Full project analysis"
|
||||||
|
echo " claude-project deps # Dependency analysis"
|
||||||
|
echo " claude-project security # Security audit"
|
||||||
|
echo " claude-project performance # Performance review"
|
||||||
|
echo " claude-project architecture # Architecture review"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Session management examples
|
||||||
|
echo "💾 Session Management:"
|
||||||
|
echo " claude-session list # List sessions"
|
||||||
|
echo " claude-session save my_work # Save current session"
|
||||||
|
echo " claude-session load abc123 # Load session"
|
||||||
|
echo " claude-session clean # Clean old sessions"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Advanced usage examples
|
||||||
|
echo "🎯 Advanced Usage:"
|
||||||
|
echo " # Combine multiple flags"
|
||||||
|
echo " cc --model sonnet --verbose --add-dir ../lib 'analyze project'"
|
||||||
|
echo ""
|
||||||
|
echo " # Use with output formatting"
|
||||||
|
echo " ccp --output-format json 'get project stats' | jq '.'"
|
||||||
|
echo ""
|
||||||
|
echo " # Chain operations"
|
||||||
|
echo " git diff --cached | claude-pipe-enhanced code 'review changes' && claude-git commit"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Workflow examples
|
||||||
|
echo "🔄 Common Workflows:"
|
||||||
|
echo ""
|
||||||
|
echo " # Code Review Workflow:"
|
||||||
|
echo " git diff --cached | claude-pipe-enhanced code 'review these changes'"
|
||||||
|
echo " claude-git commit"
|
||||||
|
echo " claude-git pr 'description of changes'"
|
||||||
|
echo ""
|
||||||
|
echo " # Debugging Workflow:"
|
||||||
|
echo " npm test 2>&1 | claude-pipe-enhanced error 'analyze test failures'"
|
||||||
|
echo " claude-quick fix 'specific error from above'"
|
||||||
|
echo " npm test # Run tests again"
|
||||||
|
echo ""
|
||||||
|
echo " # Project Setup Workflow:"
|
||||||
|
echo " claude-project analyze"
|
||||||
|
echo " claude-project deps"
|
||||||
|
echo " claude-project security"
|
||||||
|
echo " claude-quick docs 'setup instructions'"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Tips and tricks
|
||||||
|
echo "💡 Tips and Tricks:"
|
||||||
|
echo ""
|
||||||
|
echo " # Use Tab completion for all commands and flags"
|
||||||
|
echo " cc --<TAB> # See all available flags"
|
||||||
|
echo " claude-quick <TAB> # See all quick actions"
|
||||||
|
echo " claude-git <TAB> # See all git actions"
|
||||||
|
echo ""
|
||||||
|
echo " # Combine with other tools"
|
||||||
|
echo " watch -n 5 'npm test 2>&1 | claude-pipe-enhanced error \"monitor tests\"'"
|
||||||
|
echo ""
|
||||||
|
echo " # Save frequently used queries"
|
||||||
|
echo " alias ccbug='claude-quick debug'"
|
||||||
|
echo " alias ccopt='claude-quick optimize'"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "📚 For more information, see the README.md file or visit:"
|
||||||
|
echo " https://docs.anthropic.com/en/docs/claude-code/"
|
||||||
209
plugins/claudecode/test_plugin.zsh
Executable file
209
plugins/claudecode/test_plugin.zsh
Executable file
|
|
@ -0,0 +1,209 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
# Test script for ClaudeCode Oh My Zsh plugin
|
||||||
|
# This script tests the basic functionality of the plugin
|
||||||
|
|
||||||
|
echo "🧪 Testing ClaudeCode Oh My Zsh Plugin"
|
||||||
|
echo "======================================"
|
||||||
|
|
||||||
|
# Set up test environment
|
||||||
|
export ZSH_CACHE_DIR="/tmp/test_claudecode_cache"
|
||||||
|
mkdir -p "$ZSH_CACHE_DIR"
|
||||||
|
|
||||||
|
# Source the plugin
|
||||||
|
echo "📦 Loading plugin..."
|
||||||
|
source "./claudecode.plugin.zsh"
|
||||||
|
|
||||||
|
# Test 1: Check if aliases are defined
|
||||||
|
echo "🔍 Testing aliases..."
|
||||||
|
test_aliases() {
|
||||||
|
local aliases=("cc" "ccp" "ccc" "ccr" "ccv" "ccu" "ccm" "cccommit" "ccpr" "ccreview" "cctest" "cclint" "ccdocs" "ccsonnet" "ccopus" "cchaiku")
|
||||||
|
local failed=0
|
||||||
|
|
||||||
|
for alias_name in "${aliases[@]}"; do
|
||||||
|
if alias "$alias_name" >/dev/null 2>&1; then
|
||||||
|
echo " ✅ Alias '$alias_name' is defined"
|
||||||
|
else
|
||||||
|
echo " ❌ Alias '$alias_name' is NOT defined"
|
||||||
|
((failed++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return $failed
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test 2: Check if functions are defined
|
||||||
|
echo "🔍 Testing functions..."
|
||||||
|
test_functions() {
|
||||||
|
local functions=("claude-quick" "claude-pipe" "claude-git" "claude-project" "claude-session" "claude-pipe-enhanced" "_claude_quick" "_claude_git" "_claude_project" "_claude_session")
|
||||||
|
local failed=0
|
||||||
|
|
||||||
|
for func_name in "${functions[@]}"; do
|
||||||
|
if declare -f "$func_name" >/dev/null 2>&1; then
|
||||||
|
echo " ✅ Function '$func_name' is defined"
|
||||||
|
else
|
||||||
|
echo " ❌ Function '$func_name' is NOT defined"
|
||||||
|
((failed++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return $failed
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test 3: Test claude-quick function
|
||||||
|
echo "🔍 Testing claude-quick function..."
|
||||||
|
test_claude_quick() {
|
||||||
|
local output
|
||||||
|
output=$(claude-quick 2>&1)
|
||||||
|
|
||||||
|
if [[ $output == *"Usage: claude-quick"* ]]; then
|
||||||
|
echo " ✅ claude-quick shows usage when called without arguments"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo " ❌ claude-quick does not show expected usage message"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test 4: Test claude-pipe function
|
||||||
|
echo "🔍 Testing claude-pipe function..."
|
||||||
|
test_claude_pipe() {
|
||||||
|
local output
|
||||||
|
output=$(claude-pipe 2>&1)
|
||||||
|
|
||||||
|
if [[ $output == *"Usage: command | claude-pipe"* ]]; then
|
||||||
|
echo " ✅ claude-pipe shows usage when called without pipe"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo " ❌ claude-pipe does not show expected usage message"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test 5: Check if completion cache functions exist
|
||||||
|
echo "🔍 Testing cache functions..."
|
||||||
|
test_cache_functions() {
|
||||||
|
local functions=("_claudecode_get_version" "_claudecode_cache_valid" "_claudecode_generate_completion")
|
||||||
|
local failed=0
|
||||||
|
|
||||||
|
for func_name in "${functions[@]}"; do
|
||||||
|
if declare -f "$func_name" >/dev/null 2>&1; then
|
||||||
|
echo " ✅ Cache function '$func_name' is defined"
|
||||||
|
else
|
||||||
|
echo " ❌ Cache function '$func_name' is NOT defined"
|
||||||
|
((failed++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return $failed
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test 6: Test completion generation (mock)
|
||||||
|
echo "🔍 Testing completion generation..."
|
||||||
|
test_completion_generation() {
|
||||||
|
# Mock claude command for testing
|
||||||
|
claude() {
|
||||||
|
echo "Claude Code CLI v1.0.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test version function
|
||||||
|
local version
|
||||||
|
version=$(_claudecode_get_version)
|
||||||
|
|
||||||
|
if [[ -n "$version" ]]; then
|
||||||
|
echo " ✅ Version detection works: $version"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo " ❌ Version detection failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run all tests
|
||||||
|
echo ""
|
||||||
|
echo "🚀 Running tests..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
failed_tests=0
|
||||||
|
|
||||||
|
test_aliases
|
||||||
|
((failed_tests += $?))
|
||||||
|
|
||||||
|
test_functions
|
||||||
|
((failed_tests += $?))
|
||||||
|
|
||||||
|
test_claude_quick
|
||||||
|
((failed_tests += $?))
|
||||||
|
|
||||||
|
test_claude_pipe
|
||||||
|
((failed_tests += $?))
|
||||||
|
|
||||||
|
test_cache_functions
|
||||||
|
((failed_tests += $?))
|
||||||
|
|
||||||
|
test_completion_generation
|
||||||
|
((failed_tests += $?))
|
||||||
|
|
||||||
|
# Test 7: Test new helper functions
|
||||||
|
echo "🔍 Testing new helper functions..."
|
||||||
|
test_new_functions() {
|
||||||
|
local failed=0
|
||||||
|
|
||||||
|
# Test claude-git function
|
||||||
|
local output
|
||||||
|
output=$(claude-git 2>&1)
|
||||||
|
if [[ $output == *"Usage: claude-git"* ]]; then
|
||||||
|
echo " ✅ claude-git shows usage when called without arguments"
|
||||||
|
else
|
||||||
|
echo " ❌ claude-git does not show expected usage message"
|
||||||
|
((failed++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test claude-project function
|
||||||
|
output=$(claude-project 2>&1)
|
||||||
|
if [[ $output == *"Usage: claude-project"* ]]; then
|
||||||
|
echo " ✅ claude-project shows usage when called without arguments"
|
||||||
|
else
|
||||||
|
echo " ❌ claude-project does not show expected usage message"
|
||||||
|
((failed++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test claude-session function
|
||||||
|
output=$(claude-session 2>&1)
|
||||||
|
if [[ $output == *"Usage: claude-session"* ]]; then
|
||||||
|
echo " ✅ claude-session shows usage when called without arguments"
|
||||||
|
else
|
||||||
|
echo " ❌ claude-session does not show expected usage message"
|
||||||
|
((failed++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test claude-pipe-enhanced function
|
||||||
|
output=$(claude-pipe-enhanced 2>&1)
|
||||||
|
if [[ $output == *"Usage: command | claude-pipe-enhanced"* ]]; then
|
||||||
|
echo " ✅ claude-pipe-enhanced shows usage when called without pipe"
|
||||||
|
else
|
||||||
|
echo " ❌ claude-pipe-enhanced does not show expected usage message"
|
||||||
|
((failed++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $failed
|
||||||
|
}
|
||||||
|
|
||||||
|
test_new_functions
|
||||||
|
((failed_tests += $?))
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
echo ""
|
||||||
|
echo "📊 Test Summary"
|
||||||
|
echo "==============="
|
||||||
|
|
||||||
|
if [[ $failed_tests -eq 0 ]]; then
|
||||||
|
echo "🎉 All tests passed! The plugin is working correctly."
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "❌ $failed_tests test(s) failed. Please check the plugin implementation."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -rf "$ZSH_CACHE_DIR"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue