Skip to content

Commit a5d49bd

Browse files
0xkazclaude
andcommitted
✨ Add template system for reusable commit messages (v0.0.5)
New features: - Add template management system - Save templates: --save-template <name> "<template>" - Use templates: --template <name> or -T <name> - List templates: --list-templates - Delete templates: --delete-template <name> - Support smart placeholders with {variable} syntax - Prompts for values when using templates - Multiple placeholders per template supported - Templates stored in ~/.claude-auto-commit/templates/ Examples: - Save: claude-auto-commit --save-template hotfix "🔥 HOTFIX: {description}" - Use: claude-auto-commit --template hotfix - List: claude-auto-commit --list-templates Documentation: - Update README with template examples - Add template section to FEATURES.md - Update CHANGELOG for v0.0.5 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 62cdac2 commit a5d49bd

File tree

4 files changed

+159
-8
lines changed

4 files changed

+159
-8
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.0.5] - 2024-06-13
9+
10+
### Added
11+
- **Template System** for saving and reusing commit message patterns
12+
- `--save-template <name> "<template>"` to save a template
13+
- `--template <name>` or `-T <name>` to use a saved template
14+
- `--list-templates` to show all saved templates
15+
- `--delete-template <name>` to remove a template
16+
- **Smart placeholders** in templates using `{variable}` syntax
17+
- Prompts for values when using templates with placeholders
18+
- Supports multiple placeholders in a single template
19+
- Example: `🔥 HOTFIX: {description} - fixes {issue}`
20+
- Templates stored in `~/.claude-auto-commit/templates/`
21+
822
## [0.0.4] - 2024-06-13
923

1024
### Added

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ claude-auto-commit -l en -e -t feat
4444
- 📋 **Change Summary**: Detailed statistics about your changes (lines added/deleted, file types)
4545
- 🧠 **Commit Learning**: Analyze your commit history to maintain consistent style
4646
- 🎯 **Smart Grouping**: Intelligently categorize files for logical commits
47+
- 📝 **Template System**: Save and reuse common commit message patterns
4748
-**Lightweight**: Shell script with minimal dependencies
4849
- 🛠️ **Configurable**: Extensive customization through CLI options and config files
4950

@@ -132,6 +133,11 @@ claude-auto-commit --summary
132133
# Combine options for detailed preview
133134
claude-auto-commit --dry-run --summary -v
134135

136+
# Template management
137+
claude-auto-commit --save-template hotfix "🔥 HOTFIX: {description}"
138+
claude-auto-commit --template hotfix
139+
claude-auto-commit --list-templates
140+
135141
# Update tool
136142
claude-auto-commit --update
137143
```
@@ -180,12 +186,14 @@ git:
180186
auto_push: true
181187
```
182188
183-
## 🚀 What's New in v0.0.4
189+
## 🚀 What's New in v0.0.5
184190
185-
- **Smart Grouping**: Analyze and categorize files for logical commits with `--smart-group`
186-
- **Commit History Learning**: Learn from your project's commit style with `--analyze-history`
187-
- **Learned Style**: Apply analyzed patterns to new commits with `--style learned`
188-
- **macOS Compatibility**: Fixed compatibility issues for macOS users
191+
- **Template System**: Save and reuse commit message templates
192+
- Save templates: `--save-template <name> "<template>"`
193+
- Use templates: `--template <name>` or `-T <name>`
194+
- List templates: `--list-templates`
195+
- Delete templates: `--delete-template <name>`
196+
- **Smart placeholders**: Use `{variable}` in templates for dynamic values
189197

190198
## 🤝 Contributing
191199

docs/FEATURES.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,36 @@ Apply analyzed patterns to new commits:
167167
claude-auto-commit --style learned
168168
```
169169

170+
## New Features (v0.0.5)
171+
172+
### 📝 Template System
173+
Save and reuse common commit message patterns:
174+
175+
```bash
176+
# Save a template
177+
claude-auto-commit --save-template hotfix "🔥 HOTFIX: {description}"
178+
claude-auto-commit --save-template deps "⬆️ Update {package} from {old_version} to {new_version}"
179+
claude-auto-commit --save-template wip "[WIP] {feature}: {status}"
180+
181+
# Use a template
182+
claude-auto-commit --template hotfix
183+
# Prompts: Enter value for description: [user input]
184+
# Result: 🔥 HOTFIX: [user input]
185+
186+
# Short form
187+
claude-auto-commit -T deps
188+
189+
# List all templates
190+
claude-auto-commit --list-templates
191+
192+
# Delete a template
193+
claude-auto-commit --delete-template wip
194+
```
195+
196+
Templates support placeholders with `{variable}` syntax. When using a template with placeholders, you'll be prompted to enter values for each variable.
197+
170198
## Upcoming Features
171199

172-
- 📝 **Template System**: Save and reuse common commit message patterns
173200
- ✂️ **Split Commits**: Break large changes into logical commits
174201
- 🔧 **Selective Analysis**: Filter files to include/exclude from analysis
175202
- 🔗 **Git Hook Integration**: Automatic message generation on commit

src/claude-auto-commit.sh

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

33
# Claude Auto-Commit - AI-powered Git commit message generator
4-
# Version: 0.0.4
4+
# Version: 0.0.5
55
# Homepage: https://claude-auto-commit.0xkaz.com
66

7-
VERSION="0.0.4"
7+
VERSION="0.0.5"
88
REPO="0xkaz/claude-auto-commit"
99
CONFIG_DIR="$HOME/.claude-auto-commit"
1010
CONFIG_FILE="$CONFIG_DIR/config.yml"
@@ -26,6 +26,10 @@ SHOW_SUMMARY=false
2626
SMART_GROUP=false
2727
ANALYZE_HISTORY=false
2828
USE_LEARNED_STYLE=false
29+
SAVE_TEMPLATE=""
30+
USE_TEMPLATE=""
31+
LIST_TEMPLATES=false
32+
DELETE_TEMPLATE=""
2933

3034
# Display usage information
3135
usage() {
@@ -50,6 +54,10 @@ Options:
5054
--smart-group Group related files into logical commits
5155
--analyze-history Analyze commit history to learn patterns
5256
--style learned Use learned commit style from history
57+
--save-template <name> Save a commit message template
58+
--template <name> Use a saved template (-T for short)
59+
--list-templates List all saved templates
60+
--delete-template <name> Delete a saved template
5361
--update Check for updates now
5462
--no-update Skip update check
5563
--version Show version information
@@ -62,6 +70,8 @@ Examples:
6270
$(basename $0) --dry-run # Generate message only
6371
$(basename $0) --smart-group # Group related files
6472
$(basename $0) --analyze-history # Learn from commit history
73+
$(basename $0) --save-template hotfix "🔥 HOTFIX: {description}"
74+
$(basename $0) --template hotfix # Use saved template
6575
EOF
6676
}
6777

@@ -264,6 +274,23 @@ while [[ $# -gt 0 ]]; do
264274
fi
265275
shift 2
266276
;;
277+
--save-template)
278+
SAVE_TEMPLATE="$2"
279+
CUSTOM_MESSAGE="$3"
280+
shift 3
281+
;;
282+
--template|-T)
283+
USE_TEMPLATE="$2"
284+
shift 2
285+
;;
286+
--list-templates)
287+
LIST_TEMPLATES=true
288+
shift
289+
;;
290+
--delete-template)
291+
DELETE_TEMPLATE="$2"
292+
shift 2
293+
;;
267294
--update)
268295
# Force update
269296
AUTO_UPDATE=true
@@ -295,12 +322,56 @@ done
295322
# Create config directory
296323
mkdir -p "$CONFIG_DIR"
297324

325+
# Create templates directory
326+
TEMPLATES_DIR="$CONFIG_DIR/templates"
327+
mkdir -p "$TEMPLATES_DIR"
328+
298329
# Load config
299330
load_config
300331

301332
# Auto-update check
302333
check_for_updates "$@"
303334

335+
# Template management functions
336+
if [ "$LIST_TEMPLATES" = true ]; then
337+
print_info "📝 Available templates:"
338+
if [ -d "$TEMPLATES_DIR" ] && [ "$(ls -A "$TEMPLATES_DIR" 2>/dev/null)" ]; then
339+
for template in "$TEMPLATES_DIR"/*; do
340+
[ -f "$template" ] && {
341+
name=$(basename "$template")
342+
content=$(cat "$template")
343+
echo "$name: $content"
344+
}
345+
done
346+
else
347+
echo " No templates found."
348+
echo " Create one with: $(basename $0) --save-template <name> \"<template>\""
349+
fi
350+
exit 0
351+
fi
352+
353+
if [ -n "$DELETE_TEMPLATE" ]; then
354+
if [ -f "$TEMPLATES_DIR/$DELETE_TEMPLATE" ]; then
355+
rm "$TEMPLATES_DIR/$DELETE_TEMPLATE"
356+
print_success "Template '$DELETE_TEMPLATE' deleted"
357+
else
358+
print_error "Template '$DELETE_TEMPLATE' not found"
359+
fi
360+
exit 0
361+
fi
362+
363+
if [ -n "$SAVE_TEMPLATE" ]; then
364+
if [ -z "$CUSTOM_MESSAGE" ]; then
365+
print_error "Template content required"
366+
echo "Usage: $(basename $0) --save-template <name> \"<template>\""
367+
exit 1
368+
fi
369+
echo "$CUSTOM_MESSAGE" > "$TEMPLATES_DIR/$SAVE_TEMPLATE"
370+
print_success "Template '$SAVE_TEMPLATE' saved"
371+
echo "Use it with: $(basename $0) --template $SAVE_TEMPLATE"
372+
exit 0
373+
fi
374+
304375
# Check if we're in a Git repository
305376
if ! git rev-parse --git-dir > /dev/null 2>&1; then
306377
print_error "Not a Git repository"
@@ -491,6 +562,37 @@ if [ "$AUTO_STAGE" = false ]; then
491562
fi
492563
fi
493564

565+
# Use template if specified
566+
if [ -n "$USE_TEMPLATE" ]; then
567+
if [ -f "$TEMPLATES_DIR/$USE_TEMPLATE" ]; then
568+
TEMPLATE_CONTENT=$(cat "$TEMPLATES_DIR/$USE_TEMPLATE")
569+
print_info "Using template: $USE_TEMPLATE"
570+
571+
# Process template placeholders
572+
if echo "$TEMPLATE_CONTENT" | grep -q "{"; then
573+
# Extract placeholders
574+
PLACEHOLDERS=$(echo "$TEMPLATE_CONTENT" | grep -o '{[^}]*}' | sort -u)
575+
576+
# Replace each placeholder
577+
FINAL_MESSAGE="$TEMPLATE_CONTENT"
578+
for placeholder in $PLACEHOLDERS; do
579+
var_name=$(echo "$placeholder" | tr -d '{}')
580+
echo
581+
read -p "Enter value for $var_name: " -r var_value
582+
FINAL_MESSAGE=$(echo "$FINAL_MESSAGE" | sed "s/$placeholder/$var_value/g")
583+
done
584+
CUSTOM_MESSAGE="$FINAL_MESSAGE"
585+
else
586+
CUSTOM_MESSAGE="$TEMPLATE_CONTENT"
587+
fi
588+
else
589+
print_error "Template '$USE_TEMPLATE' not found"
590+
print_info "Available templates:"
591+
ls "$TEMPLATES_DIR" 2>/dev/null | sed 's/^/ • /' || echo " No templates found"
592+
exit 1
593+
fi
594+
fi
595+
494596
# Generate message with Claude CLI if no custom message provided
495597
if [ -z "$CUSTOM_MESSAGE" ]; then
496598
# Get detailed changes and save to temp file

0 commit comments

Comments
 (0)