From 2eea6c8a43c08da2ee4a8c0a79ffd5f35b7e274b Mon Sep 17 00:00:00 2001 From: "Eshan Roy (Eshanized)" <148610067+eshanized@users.noreply.github.com> Date: Sun, 16 Jun 2024 02:18:23 +0530 Subject: [PATCH] [refactor] enhancement --- push.sh | 59 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/push.sh b/push.sh index d3b5dce..6a9a7e4 100755 --- a/push.sh +++ b/push.sh @@ -1,32 +1,41 @@ #!/bin/bash -# Author : Eshan Roy -# URI : https://eshanized.github.io +# Stage all changes +git add . -# NOTE: If you are on Snigdha OS, -# you can install commitizen-go with `sudo pacman -S commitizen-go` -# or `s commitizen-go`. Else you need to install `yay` or `yay-bin` -# to install commitizen. I have written this script only for *Arch Linux. +# Define the conventional commit types +TYPES=("feat" "fix" "docs" "style" "refactor" "perf" "test" "build" "ci" "chore" "revert") -# Function to check if Commitizen is installed -check_commitizen() { - if ! pacman -Qq commitizen-go &> /dev/null; then - echo "Commitizen is not installed. Please install it using 'yay -S commitizen-go'." >&2 - exit 1 - fi -} +# Prompt the user to select a commit type +echo "Select a commit type:" +select type in "${TYPES[@]}"; do + break +done -# Function to stage, commit, and push changes -push_to_github() { - git add . - git cz - git push origin master -} +# Prompt the user to enter a short description +read -p "Enter a short description: " desc -# Main Function -main() { - check_commitizen - push_to_github -} +# Prompt the user to enter a longer description (optional) +read -p "Enter a longer description (optional): " long_desc -main +# Create the commit message +commit_msg="[$type] $desc" + +# If a longer description was provided, add it to the commit message +if [ -n "$long_desc" ]; then + commit_msg+=" + +$long_desc" +fi + +# Print the commit message to the console +echo "Commit message:" +echo "$commit_msg" + + + +# Commit the changes with the conventional commit message +git commit -m "$commit_msg" + +# Push the changes to the remote repository +git push origin $(git rev-parse --abbrev-ref HEAD) \ No newline at end of file