2023-08-06 01:08:38 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
get_new_posts() {
|
|
|
|
git status --porcelain=v1 _posts | grep -E '^\?\?' | cut -d ' ' -f 2 | tr '\n' ' '
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to generate the commit message
|
|
|
|
generate_commit_message() {
|
|
|
|
printf "New posts: "
|
|
|
|
get_new_posts
|
|
|
|
}
|
|
|
|
|
2023-08-06 21:43:41 +08:00
|
|
|
commit_msg="$(generate_commit_message)"
|
|
|
|
|
2023-08-06 01:08:38 +08:00
|
|
|
# Check if there are any new or modified files to commit
|
|
|
|
if [ -n "$(get_new_posts)" ]; then
|
|
|
|
# Add all new and modified files
|
2023-08-06 21:43:41 +08:00
|
|
|
echo "$commit_msg"
|
2023-08-06 01:08:38 +08:00
|
|
|
git add $(get_new_posts)
|
|
|
|
|
|
|
|
# Commit the changes with the generated message
|
2023-08-06 21:43:41 +08:00
|
|
|
git commit -m "$commit_msg"
|
2023-08-06 01:08:38 +08:00
|
|
|
git push
|
|
|
|
echo "Changes committed successfully."
|
|
|
|
else
|
|
|
|
echo "No new or modified files to commit."
|
|
|
|
fi
|