#!/bin/bash # Auto-commit script for timeshift project # Usage: ./auto-commit.sh [message] set -e # Function to auto-commit changes auto_commit() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') # Check if there are any changes if [[ -n $(git status --porcelain) ]]; then echo "๐Ÿ”„ Auto-committing changes at $timestamp" # Add all changes git add . # Create commit message if [[ -z "$message" ]]; then message="Auto-commit: Save work in progress" fi # Commit with timestamp git commit -m "$(cat < EOF )" echo "โœ… Changes committed successfully" # Show short log git log --oneline -3 else echo "๐Ÿ“ No changes to commit at $timestamp" fi } # Function to create a safe restore point create_restore_point() { local description="$1" local branch_name="restore-point-$(date '+%Y%m%d-%H%M%S')" echo "๐Ÿ”– Creating restore point: $branch_name" # Commit current changes first auto_commit "Save before creating restore point: $description" # Create a new branch as restore point git branch "$branch_name" echo "โœ… Restore point created: $branch_name" echo "๐Ÿ“‹ To restore later, run: git checkout $branch_name" } # Function to show available restore points list_restore_points() { echo "๐Ÿ“‹ Available restore points:" git branch | grep "restore-point-" | sed 's/^..//' | sort -r } # Function to clean old restore points (keep last 10) cleanup_restore_points() { echo "๐Ÿงน Cleaning old restore points (keeping last 10)..." git branch | grep "restore-point-" | sed 's/^..//' | sort -r | tail -n +11 | while read branch; do git branch -D "$branch" 2>/dev/null && echo "๐Ÿ—‘๏ธ Deleted old restore point: $branch" done } # Main script logic case "$1" in "commit") auto_commit "$2" ;; "restore-point") create_restore_point "$2" ;; "list") list_restore_points ;; "cleanup") cleanup_restore_points ;; *) echo "๐Ÿ“š Auto-commit utility for timeshift project" echo "" echo "Usage:" echo " $0 commit [message] - Auto-commit current changes" echo " $0 restore-point [desc] - Create a restore point branch" echo " $0 list - List available restore points" echo " $0 cleanup - Clean old restore points" echo "" echo "Examples:" echo " $0 commit 'Fixed spreadsheet layout'" echo " $0 restore-point 'Before major refactor'" echo "" auto_commit "$1" ;; esac