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 "
88REPO=" 0xkaz/claude-auto-commit"
99CONFIG_DIR=" $HOME /.claude-auto-commit"
1010CONFIG_FILE=" $CONFIG_DIR /config.yml"
@@ -26,6 +26,10 @@ SHOW_SUMMARY=false
2626SMART_GROUP=false
2727ANALYZE_HISTORY=false
2828USE_LEARNED_STYLE=false
29+ SAVE_TEMPLATE=" "
30+ USE_TEMPLATE=" "
31+ LIST_TEMPLATES=false
32+ DELETE_TEMPLATE=" "
2933
3034# Display usage information
3135usage () {
@@ -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
6575EOF
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
296323mkdir -p " $CONFIG_DIR "
297324
325+ # Create templates directory
326+ TEMPLATES_DIR=" $CONFIG_DIR /templates"
327+ mkdir -p " $TEMPLATES_DIR "
328+
298329# Load config
299330load_config
300331
301332# Auto-update check
302333check_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
305376if ! 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
492563fi
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
495597if [ -z " $CUSTOM_MESSAGE " ]; then
496598 # Get detailed changes and save to temp file
0 commit comments