Skip to content

Instantly share code, notes, and snippets.

@paulera
Last active November 16, 2020 11:33
Show Gist options
  • Save paulera/eda5234c5d3cd7b9e2f7e3e853985bce to your computer and use it in GitHub Desktop.
Save paulera/eda5234c5d3cd7b9e2f7e3e853985bce to your computer and use it in GitHub Desktop.
Watch for changes in a folder and commit with changes as message. Kinda like Google Drive using Git.
#!/bin/bash
#
# HAVE TO REVIEW THIS SCRIPT
#
FOLDER="/folder/to/watch/for/changes"
SLEEP_INTERVAL=3
SLEEP="(- -) Zzz..."
WORKING="(# #) Working"
echo -ne "\e]0;$SLEEP\a"
cd $FOLDER
if [ "$1" == "watch" ]; then
clear
while :; do
$0
sleep $SLEEP_INTERVAL
done
else
if [ ! -z "$(git status -s)" ]; then
echo -ne "\e]0;$WORKING\a"
MESSAGE="$(git diff * | cat | grep "^+" | grep -v "^+++" | grep -v "^[+ \t]\+$")"
git add .
git commit -m "$MESSAGE"
git push
echo
cecho green "$MESSAGE\n"
echo
echo -ne "\e]0;$SLEEP\a"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment