diff --git a/git_auto_save.sh b/git_auto_save.sh new file mode 100644 index 0000000..1e52ba2 --- /dev/null +++ b/git_auto_save.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +echo 'Auto Syncing' + +while true +do + # check every 30s + sleep 30 + + # sync only 5min after last modifiication to avoid too many temperaty updates + last_modified=`find ./ -type f -exec stat \{} --printf="%Y\n" \; | sort -n -r | head -n 1` + current=`date +%s` + if (( ${current} - ${last_modified} < 300 )); then + continue + fi + + # commit changes -> pull rebase -> push to remote + no_output=`git diff-index --quiet HEAD --` + is_dirty=$? + + if [ -n "$(git status --porcelain)" ]; then + is_dirty=1 + fi + + if test "$is_dirty" = 0; then + continue + fi + + git add . -A + git commit -am "Auto update by $(whoami)" + git pull --rebase + git push origin master + +done \ No newline at end of file