Files
bash_testing/git_automation.sh
2025-12-23 15:52:12 +00:00

42 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
#Before running this script, make sure that you added an alias to your shell config file (~/.bashrc, ~/.zshrc, etc.)
#alias trigger_git='touch /tmp/please_update'
#Then run source ~/.zshrc to load the new alias
#Variable to store the trigger file path
TRIGGER_FILE="/tmp/please_update"
#The magic itself
echo "[INFO] Watching $TRIGGER_FILE..."
echo "[INFO] To trigger a git commit and push, run: trigger_git"
echo "PLEASE make sure that you have a good .gitignore file set up to avoid committing unwanted files."
#Do not know if the runs forrever loop is the best way to do this but it works
while true; do
if [[ -f "$TRIGGER_FILE" ]]; then
rm -f "$TRIGGER_FILE"
echo "[INFO] Triggered at $(date)"
read -rp "Enter commit message: " COMMIT_MSG </dev/tty
if [[ -z "$COMMIT_MSG" ]]; then
COMMIT_MSG="Committed"
fi
# Run Git commands
git status
sleep 0.5
git add .
sleep 0.5
git commit -m "$COMMIT_MSG"
sleep 0.5
git push
echo "[INFO] Git commands completed at $(date)"
fi
sleep 0.5
done