public
Created

git_inotify-commit.sh

  • Download Gist
git_inotify-commit.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/bin/sh
 
# Originally by Bjoern Steinbrink, simplified by Johannes Schindelin
# http://git.661346.n2.nabble.com/inotify-commit-was-Re-git-guidance-td3534419.html
 
inotifywait -m -r --exclude ^\./\.git/.* \
-e close_write -e move -e create -e delete . 2>/dev/null |
while read FILE_PATH EVENT FILE_NAME
do
FILE_NAME="$FILE_PATH$FILE_NAME"
FILE_NAME=${FILE_NAME#./}
 
# git doesn't care about directories
test -d "$FILE_NAME" && continue
 
case "$EVENT" in
*MOVED_TO*|*CREATE*)
git add "$FILE_NAME"
git commit -m "$FILE_NAME created"
;;
*CLOSE_WRITE*|*MODIFY*)
git add "$FILE_NAME"
git commit -m "$FILE_NAME changed"
;;
*DELETE*|*MOVED_FROM*)
git rm --cached "$FILE_NAME"
git commit -m "$FILE_NAME removed"
;;
esac
done

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.