Skip to content

Instantly share code, notes, and snippets.

@harperreed
Created January 9, 2012 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harperreed/1585111 to your computer and use it in GitHub Desktop.
Save harperreed/1585111 to your computer and use it in GitHub Desktop.
git_inotify-commit.sh
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment