-
-
Save sandalsoft/32134d9579a55172f3f2719a2a7db113 to your computer and use it in GitHub Desktop.
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
| function gc() { | |
| # Stage all changes | |
| git add . | |
| CHAR_LIMIT=900 | |
| # Get the staged changes using git diff | |
| STAGED_CHANGES=$(PAGER="" git diff --cached) | |
| if [ -z "$STAGED_CHANGES" ]; then | |
| echo "No staged changes found. Please stage your changes first using 'git add'" | |
| return 1 | |
| fi | |
| # Check if a message prefix was provided as an argument | |
| USER_PREFIX="" | |
| if [ "$#" -gt 0 ]; then | |
| USER_PREFIX="$* - " | |
| fi | |
| # Use aichat to generate commit message based on the changes | |
| COMMIT_MESSAGE=$(echo "Create a concise git commit message (no more than $CHAR_LIMIT chars) describing these changes: $STAGED_CHANGES" | aichat) | |
| # Prepend the user's text if provided | |
| FINAL_COMMIT_MESSAGE="${USER_PREFIX}${COMMIT_MESSAGE}" | |
| # Display the generated message and ask for confirmation | |
| echo -e "\nGenerated commit message:\n$FINAL_COMMIT_MESSAGE" | |
| echo -n "Do you want to use this commit message? (y/n) " | |
| read confirm </dev/tty # Force reading from terminal | |
| if [ "$confirm" = "y" ]; then | |
| git commit -m "$FINAL_COMMIT_MESSAGE" | |
| echo "Changes committed successfully!" | |
| git push | |
| echo "Changes pushed successfully!" | |
| else | |
| echo "Commit cancelled" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment