Skip to content

Instantly share code, notes, and snippets.

@rokde
Created April 12, 2026 13:39
Show Gist options
  • Select an option

  • Save rokde/82bc7ed14f070a5b7a8b2422f9c96b6a to your computer and use it in GitHub Desktop.

Select an option

Save rokde/82bc7ed14f070a5b7a8b2422f9c96b6a to your computer and use it in GitHub Desktop.
commit.sh
commit() {
local files=()
local ask_confirmation=false
local diff_content
local commit_msg
local arg
# Argumente parsen
for arg in "$@"; do
if [ "$arg" = "--ask" ]; then
ask_confirmation=true
else
files+=("$arg")
fi
done
# 1. Diff sammeln
if [ ${#files[@]} -eq 0 ]; then
echo "🔍 Analysiere alle Änderungen..."
diff_content=$(git diff HEAD)
else
echo "🔍 Analysiere Änderungen für: ${files[*]}..."
diff_content=$(git diff HEAD -- "${files[@]}")
fi
if [ -z "$diff_content" ]; then
echo "❌ Keine Änderungen zum Committen gefunden."
return 1
fi
# 2. KI-Prompt an Claude
echo "🤖 Claude generiert Commit-Message..."
commit_msg=$(echo "$diff_content" | claude "Generate a concise git commit message in Conventional Commits format based on this diff.
Use types like feat, fix, docs, style, refactor, test, or chore.
Only return the message text, no explanations or markdown backticks.")
if [ -z "$commit_msg" ]; then
echo "❌ Claude konnte keine Nachricht generieren."
return 1
fi
echo -e "\nVorschlag: \"$commit_msg\""
# 3. Optionale Bestätigung
if [ "$ask_confirmation" = true ]; then
echo -n "Möchtest du diesen Commit erstellen? (y/n): "
read confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
echo "Operation abgebrochen."
return 0
fi
fi
# 4. Dateien hinzufügen und committen
if [ ${#files[@]} -eq 0 ]; then
git add .
else
git add "${files[@]}"
fi
git commit -m "$commit_msg"
# 5. Erfolgsausgabe
echo -e "\n✅ Commit erfolgreich erstellt:"
git log -1 --stat
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment