Last active
November 16, 2020 11:33
-
-
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.
This file contains hidden or 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
#!/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