Skip to content

Instantly share code, notes, and snippets.

@prabapro
Last active August 13, 2023 08:19
Show Gist options
  • Save prabapro/2015016eadc5e6888d90d975fcd09666 to your computer and use it in GitHub Desktop.
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.
#!/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