Created
July 7, 2023 04:49
-
-
Save azu/5b1def49b0737daab23d0320ce3ce67e to your computer and use it in GitHub Desktop.
git auto commit
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
function git-auto-commit(){ | |
git_status=$(git status --porcelain | grep -vE '^\s') | |
first=$(echo "$git_status" | head -n1) | |
filename=$(echo "$first" | awk '{print $NF}') | |
git_root_dir=$(git rev-parse --show-toplevel) | |
if echo "$first" | grep -Eq '^\s?M'; then | |
commit_message="Update $filename" | |
elif echo "$first" | grep -Eq '^\s?A'; then | |
commit_message="Add $filename" | |
elif echo "$first" | grep -Eq '^\s?D'; then | |
commit_message="Delete $filename" | |
elif echo "$first" | grep -Eq '^\s?R'; then | |
from=$(echo "$first" | awk '{print $2}') | |
to=$(echo "$first" | awk '{print $4}') | |
commit_message="Rename $from to $to" | |
else | |
echo "🔔 untrack file exists" | |
echo "$(git status --porcelain)" | |
# confirm to add all untrack files(Y/n/Enter) | |
echo "🤖 add all untrack files? (y/n)" | |
read answer | |
if [ "$answer" != "y" ]; then | |
return 1 | |
fi | |
git add ${git_root_dir} --verbose | |
git-auto-commit | |
return 0 | |
fi | |
git commit -m "$commit_message" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment