Created
November 15, 2025 14:27
-
-
Save iblueer/8ed22f7a9b0802fb36f89a14075adf37 to your computer and use it in GitHub Desktop.
Factory Droid Commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Droid CLI custom command for git commit | |
| # Usage: /git-commit [commit_message] | |
| # Function to display usage | |
| usage() { | |
| echo "Usage: /git-commit [commit_message]" | |
| echo " If commit_message is not provided, AI will generate one based on changes" | |
| echo "" | |
| echo "Examples:" | |
| echo " /git-commit 'feat: add new feature'" | |
| echo " /git-commit" | |
| } | |
| # Function to generate commit message using AI | |
| generate_commit_message() { | |
| echo "🤖 Generating commit message based on changes..." | |
| # Get staged changes | |
| STAGED_CHANGES=$(git diff --cached --name-status 2>/dev/null || echo "") | |
| # Get unstaged changes if no staged changes | |
| if [[ -z "$STAGED_CHANGES" ]]; then | |
| echo "No staged changes found. Checking unstaged changes..." | |
| STAGED_CHANGES=$(git diff --name-status 2>/dev/null || echo "") | |
| fi | |
| # Get file list | |
| CHANGED_FILES=$(git diff --cached --name-only 2>/dev/null || git diff --name-only 2>/dev/null || echo "") | |
| if [[ -z "$STAGED_CHANGES" && -z "$CHANGED_FILES" ]]; then | |
| echo "No changes detected. Please stage some files first with 'git add'." | |
| exit 1 | |
| fi | |
| # Create a prompt for AI | |
| AI_PROMPT="Generate a concise git commit message in conventional commit format based on these changes:\n\n" | |
| AI_PROMPT+="Changed files:\n$CHANGED_FILES\n\n" | |
| AI_PROMPT+="Changes:\n$STAGED_CHANGES\n\n" | |
| AI_PROMPT+="Format: <type>(<scope>): <description>\n\n" | |
| AI_PROMPT+="Common types: feat, fix, docs, style, refactor, perf, test, chore\n" | |
| AI_PROMPT+="Keep it short and descriptive." | |
| # Use a simple heuristic to generate commit message if AI is not available | |
| # This is a fallback - in practice, you'd want to call an AI service | |
| if [[ -n "$CHANGED_FILES" ]]; then | |
| # Count file types for heuristic | |
| FEATURE_FILES=$(echo "$CHANGED_FILES" | grep -E "(feature|feat|add|new)" | wc -l) | |
| FIX_FILES=$(echo "$CHANGED_FILES" | grep -E "(fix|bug|error|issue)" | wc -l) | |
| if [[ $FEATURE_FILES -gt 0 ]]; then | |
| COMMIT_TYPE="feat" | |
| COMMIT_DESC="add new feature" | |
| elif [[ $FIX_FILES -gt 0 ]]; then | |
| COMMIT_TYPE="fix" | |
| COMMIT_DESC="resolve issue" | |
| else | |
| COMMIT_TYPE="chore" | |
| COMMIT_DESC="update files" | |
| fi | |
| # Use first changed file as scope | |
| FIRST_FILE=$(echo "$CHANGED_FILES" | head -1 | sed 's|.*/||' | sed 's/\..*//') | |
| if [[ -n "$FIRST_FILE" ]]; then | |
| echo "${COMMIT_TYPE}(${FIRST_FILE}): ${COMMIT_DESC}" | |
| else | |
| echo "${COMMIT_TYPE}: ${COMMIT_DESC}" | |
| fi | |
| else | |
| echo "chore: update code" | |
| fi | |
| } | |
| # Check if we're in a git repository | |
| if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
| echo "Error: Not a git repository" | |
| exit 1 | |
| fi | |
| # Check for help flag | |
| if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then | |
| usage | |
| exit 0 | |
| fi | |
| # Get commit message from arguments or generate with AI | |
| COMMIT_MESSAGE="$*" | |
| if [[ -z "$COMMIT_MESSAGE" ]]; then | |
| COMMIT_MESSAGE=$(generate_commit_message) | |
| echo "🤖 AI suggests: $COMMIT_MESSAGE" | |
| echo "" | |
| echo "Press Enter to use this message, or type a custom message:" | |
| read -r CUSTOM_MESSAGE | |
| if [[ -n "$CUSTOM_MESSAGE" ]]; then | |
| COMMIT_MESSAGE="$CUSTOM_MESSAGE" | |
| fi | |
| fi | |
| # Show git status before commit | |
| echo "Current git status:" | |
| git status --short | |
| # Show what will be committed | |
| echo "" | |
| echo "Files to be committed:" | |
| git diff --cached --name-only | |
| # Confirm commit | |
| if [[ -n "$(git diff --cached --name-only)" ]]; then | |
| echo "" | |
| echo "Commit message: $COMMIT_MESSAGE" | |
| echo "Proceed with commit? (y/N)" | |
| read -r CONFIRM | |
| if [[ "$CONFIRM" != "y" ]] && [[ "$CONFIRM" != "Y" ]]; then | |
| echo "Commit cancelled" | |
| exit 0 | |
| fi | |
| # Perform the commit | |
| git commit -m "$COMMIT_MESSAGE | |
| Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>" | |
| echo "✅ Commit created successfully" | |
| echo "Commit hash: $(git rev-parse --short HEAD)" | |
| else | |
| echo "No changes staged for commit. Use 'git add' to stage changes first." | |
| exit 1 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Droid CLI custom command for undoing the last git commit | |
| # Usage: /git-undo-commit | |
| # Function to display usage | |
| usage() { | |
| echo "Usage: /git-undo-commit" | |
| echo " Undoes the last git commit and keeps changes staged" | |
| echo "" | |
| echo "This will run: git reset --soft HEAD~1" | |
| } | |
| # Check if we're in a git repository | |
| if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
| echo "Error: Not a git repository" | |
| exit 1 | |
| fi | |
| # Check for help flag | |
| if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then | |
| usage | |
| exit 0 | |
| fi | |
| # Check if there are any commits to undo | |
| if [[ "$(git rev-list --count HEAD)" -le 1 ]]; then | |
| echo "Error: No commits to undo (only one commit in repository)" | |
| exit 1 | |
| fi | |
| # Show the last commit that will be undone | |
| echo "Last commit to be undone:" | |
| git log --oneline -1 | |
| # Confirm undo | |
| echo "" | |
| echo "This will undo the last commit and keep changes staged." | |
| echo "Proceed? (y/N)" | |
| read -r CONFIRM | |
| if [[ "$CONFIRM" != "y" ]] && [[ "$CONFIRM" != "Y" ]]; then | |
| echo "Undo cancelled" | |
| exit 0 | |
| fi | |
| # Perform the undo | |
| git reset --soft HEAD~1 | |
| echo "✅ Last commit undone successfully" | |
| echo "Changes are now staged and ready for new commit" | |
| echo "" | |
| echo "Current git status:" | |
| git status --short |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment