add optional arg to specify events to monitor

pull/19/head
Phil Thompson 10 years ago
parent a2b78e9a60
commit 429c4af5bf

@ -37,6 +37,7 @@ BRANCH=""
SLEEP_TIME=2 SLEEP_TIME=2
DATE_FMT="+%Y-%m-%d %H:%M:%S" DATE_FMT="+%Y-%m-%d %H:%M:%S"
COMMITMSG="Scripted auto-commit on change (%d) by gitwatch.sh" 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 # Print a message about how to use this script
shelp () { shelp () {
@ -74,6 +75,10 @@ shelp () {
echo " (unless the <fmt> specified by -d is empty, in which case %d" echo " (unless the <fmt> specified by -d is empty, in which case %d"
echo " is replaced by an empty string); the default message is:" echo " is replaced by an empty string); the default message is:"
echo " \"Scripted auto-commit on change (%d) by gitwatch.sh\"" echo " \"Scripted auto-commit on change (%d) by gitwatch.sh\""
echo " -e <events> 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 ""
echo "As indicated, several conditions are only checked once at launch of the" 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" 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 do
case "${option}" in case "${option}" in
b) BRANCH=${OPTARG};; b) BRANCH=${OPTARG};;
@ -119,6 +124,7 @@ do
m) COMMITMSG=${OPTARG};; m) COMMITMSG=${OPTARG};;
p|r) REMOTE=${OPTARG};; p|r) REMOTE=${OPTARG};;
s) SLEEP_TIME=${OPTARG};; s) SLEEP_TIME=${OPTARG};;
e) EVENTS=${OPTARG};;
esac esac
done done
@ -151,12 +157,12 @@ IN=$(readlink -f "$1")
if [ -d "$1" ]; then # if the target is a directory 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 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_ADD_ARGS="--all ." # add "." (CWD) recursively to index
GIT_COMMIT_ARGS="" # add -a switch to "commit" call just to be sure GIT_COMMIT_ARGS="" # add -a switch to "commit" call just to be sure
elif [ -f "$1" ]; then # if the target is a single file 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 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_ADD_ARGS="$IN" # add only the selected file to index
GIT_COMMIT_ARGS="" # no need to add anything more to "commit" call GIT_COMMIT_ARGS="" # no need to add anything more to "commit" call
else else

Loading…
Cancel
Save