diff --git a/gitwatch.sh b/gitwatch.sh index 1486481..f75658d 100755 --- a/gitwatch.sh +++ b/gitwatch.sh @@ -37,6 +37,7 @@ BRANCH="" SLEEP_TIME=2 DATE_FMT="+%Y-%m-%d %H:%M:%S" COMMITMSG="Scripted auto-commit on change (%d) by gitwatch.sh" +EVENTS="close_write,move,delete,create" # Print a message about how to use this script shelp () { @@ -74,6 +75,10 @@ shelp () { echo " (unless the specified by -d is empty, in which case %d" echo " is replaced by an empty string); the default message is:" echo " \"Scripted auto-commit on change (%d) by gitwatch.sh\"" + echo " -e events passed to inotifywait to watch (defaults to " + echo " $FILE_EVENTS)" + echo " (useful when using inotify-win, e.g. -e modify,delete,move)" + echo " dir events are file events plus 'create'" echo "" echo "As indicated, several conditions are only checked once at launch of the" echo "script. You can make changes to the repo state and configurations even while" @@ -110,7 +115,7 @@ is_command () { ############################################################################### -while getopts b:d:hm:p:r:s: option # Process command line options +while getopts b:d:hm:p:r:s:e: option # Process command line options do case "${option}" in b) BRANCH=${OPTARG};; @@ -119,6 +124,7 @@ do m) COMMITMSG=${OPTARG};; p|r) REMOTE=${OPTARG};; s) SLEEP_TIME=${OPTARG};; + e) EVENTS=${OPTARG};; esac done @@ -151,12 +157,12 @@ IN=$(readlink -f "$1") if [ -d "$1" ]; then # if the target is a directory TARGETDIR=$(sed -e "s/\/*$//" <<<"$IN") # dir to CD into before using git commands: trim trailing slash, if any - INCOMMAND="\"$INW\" -qmr -e close_write,move,delete,create \"--exclude=^${TARGETDIR}/.git\" \"$TARGETDIR\"" # construct inotifywait-commandline + INCOMMAND="\"$INW\" -qmr -e $EVENTS \"--exclude=^${TARGETDIR}/.git\" \"$TARGETDIR\"" # construct inotifywait-commandline GIT_ADD_ARGS="--all ." # add "." (CWD) recursively to index GIT_COMMIT_ARGS="" # add -a switch to "commit" call just to be sure elif [ -f "$1" ]; then # if the target is a single file TARGETDIR=$(dirname "$IN") # dir to CD into before using git commands: extract from file name - INCOMMAND="\"$INW\" -qm -e close_write,move,delete \"$IN\"" # construct inotifywait-commandline + INCOMMAND="\"$INW\" -qm -e $EVENTS \"$IN\"" # construct inotifywait-commandline GIT_ADD_ARGS="$IN" # add only the selected file to index GIT_COMMIT_ARGS="" # no need to add anything more to "commit" call else