Last active
August 13, 2023 08:19
-
-
Save prabapro/2015016eadc5e6888d90d975fcd09666 to your computer and use it in GitHub Desktop.
This shell script streamlines Git commits and pushes with emoji-enhanced commit messages. It allows selecting a branch, displays files to be committed, adds emojis based on keywords, commits changes, and offers the choice to push. It adds a fun and efficient touch to Git workflows.
This file contains 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
#!/bin/bash | |
# Get the list of available branches | |
available_branches=$(git branch --list) | |
# Prompt to select a branch | |
echo "π Available branches:" | |
echo "$available_branches" | |
read -p "β Please enter the branch name to commit to (or press Enter for current branch): " selected_branch | |
if [[ -z "$selected_branch" ]]; then | |
# Use the current branch if no branch is selected | |
selected_branch=$(git symbolic-ref --short HEAD) | |
fi | |
# Switch to the selected branch | |
git checkout $selected_branch | |
# Add all files to git | |
git add -A | |
# Display the list of added files | |
added_files=$(git status --short | grep 'A ' | cut -d " " -f 3-) | |
echo "β The following files will be committed to branch '$selected_branch':" | |
echo "$added_files" | |
# Prompt for commit message | |
echo "π Please enter a commit message:" | |
read commit_message | |
# Determine the emoji based on the content of the commit message | |
if [[ $commit_message == *"fix"* ]]; then | |
emoji="π" # Bug fix | |
elif [[ $commit_message == *"readme"* ]]; then | |
emoji="βοΈ" # Update Readme | |
elif [[ $commit_message == *"feat"* ]]; then | |
emoji="β¨" # New feature | |
elif [[ $commit_message == *"docs"* ]]; then | |
emoji="π" # Documentation | |
elif [[ $commit_message == *"refactor"* ]]; then | |
emoji="π " # Refactoring | |
elif [[ $commit_message == *"rename"* ]]; then | |
emoji="βοΈ" # Renaming folders/files | |
elif [[ $commit_message == *"update"* ]]; then | |
emoji="π" # Updates | |
elif [[ $commit_message == *"style"* ]]; then | |
emoji="π" # Styling changes | |
elif [[ $commit_message == *"test"* ]]; then | |
emoji="β " # Tests | |
elif [[ $commit_message == *"chore"* ]]; then | |
emoji="π§" # Chores (maintenance tasks) | |
elif [[ $commit_message == *"merge"* ]]; then | |
emoji="π²" # Merging branches | |
elif [[ $commit_message == *"remove"* ]]; then | |
emoji="π" # Removing code/files | |
elif [[ $commit_message == *"add"* ]]; then | |
emoji="β" # Adding new code/files | |
elif [[ $commit_message == *"downgrade"* ]]; then | |
emoji="β¬οΈ" # Downgrading dependencies | |
elif [[ $commit_message == *"upgrade"* ]]; then | |
emoji="β¬οΈ" # Upgrading dependencies | |
elif [[ $commit_message == *"hotfix"* ]]; then | |
emoji="π₯" # Hotfixes | |
elif [[ $commit_message == *"security"* ]]; then | |
emoji="π" # Security-related changes | |
else | |
emoji="π¦" # Default emoji for other cases | |
fi | |
# Add the chosen emoji to the commit message | |
commit_message="$emoji $commit_message" | |
# Commit the changes with the modified message | |
git commit -m "$commit_message" | |
# Prompt to continue with push | |
read -p "β Do you want to push the commit? (y/n): " choice | |
if [[ "$choice" == "y" || "$choice" == "Y" ]]; then | |
# Push to the selected branch | |
git push origin $selected_branch | |
else | |
echo "β Push operation aborted." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment