#!/bin/bash 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 if [ -d "$FILE_NAME" ] then continue fi case "$EVENT" in *CLOSE_WRITE*) ACTION=change ;; *MOVED_TO*) ACTION=create ;; *MODIFY*) ACTION=change ;; *DELETE*) ACTION=delete ;; *MOVED_FROM*) ACTION=delete ;; *CREATE*) ACTION=create ;; *) continue ;; esac case $ACTION in create) git add "$FILE_NAME" git commit -m "$FILE_NAME created" ;; delete) git rm --cached "$FILE_NAME" git commit -m "$FILE_NAME removed" ;; change) git add "$FILE_NAME" git commit -m "$FILE_NAME changed" ;; esac done