Merge pull request #97 from harleypig/shfmt

ran gitwatch.sh through shfmt (options -i 2 -bn -ci -sr)
pull/102/head
Dave Musicant 3 years ago committed by GitHub
commit a56ae1c4b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -125,20 +125,29 @@ is_command () {
###############################################################################
while getopts b:d:h:g:L:l:m:p:r:s:e: option # Process command line options
do
while getopts b:d:h:g:L:l:m:p:r:s:e: option; do # Process command line options
case "${option}" in
b) BRANCH=${OPTARG} ;;
d) DATE_FMT=${OPTARG} ;;
h) shelp; exit;;
h)
shelp
exit
;;
g) GIT_DIR=${OPTARG} ;;
l) LISTCHANGES=${OPTARG} ;;
L) LISTCHANGES=${OPTARG}; LISTCHANGES_COLOR="";;
L)
LISTCHANGES=${OPTARG}
LISTCHANGES_COLOR=""
;;
m) COMMITMSG=${OPTARG} ;;
p | r) REMOTE=${OPTARG} ;;
s) SLEEP_TIME=${OPTARG} ;;
e) EVENTS=${OPTARG} ;;
*) stderr "Error: Option '${option}' does not exist."; shelp; exit 1;;
*)
stderr "Error: Option '${option}' does not exist."
shelp
exit 1
;;
esac
done
@ -155,25 +164,28 @@ if [ -z "$GW_GIT_BIN" ]; then GIT="git"; else GIT="$GW_GIT_BIN"; fi
if [ -z "$GW_INW_BIN" ]; then
# if Mac, use fswatch
if [ "$(uname)" != "Darwin" ]; then
INW="inotifywait";
INW="inotifywait"
EVENTS="${EVENTS:-close_write,move,move_self,delete,create,modify}"
else
INW="fswatch";
INW="fswatch"
# default events specified via a mask, see
# https://emcrisostomo.github.io/fswatch/doc/1.14.0/fswatch.html/Invoking-fswatch.html#Numeric-Event-Flags
# default of 414 = MovedTo + MovedFrom + Renamed + Removed + Updated + Created
# = 256 + 128+ 16 + 8 + 4 + 2
EVENTS="${EVENTS:---event=414}"
fi;
fi
else
INW="$GW_INW_BIN";
INW="$GW_INW_BIN"
fi
if [ -z "$GW_RL_BIN" ]; then RL="readlink"; else RL="$GW_RL_BIN"; fi
# Check availability of selected binaries and die if not met
for cmd in "$GIT" "$INW"; do
is_command "$cmd" || { stderr "Error: Required command '$cmd' not found." ; exit 2; }
is_command "$cmd" || {
stderr "Error: Required command '$cmd' not found."
exit 2
}
done
unset cmd
@ -183,7 +195,6 @@ SLEEP_PID="" # pid of timeout subprocess
trap "cleanup" EXIT # make sure the timeout is killed when exiting script
# Expand the path to the target to absolute path
if [ "$(uname)" != "Darwin" ]; then
IN=$($RL -f "$1")
@ -196,9 +207,8 @@ else
echo "Seems like your readlink doesn't support '-f'. Running without. Please 'brew install coreutils'."
IN=$($RL "$1")
fi
fi;
fi;
fi
fi
if [ -d "$1" ]; then # if the target is a directory
@ -209,7 +219,7 @@ if [ -d "$1" ]; then # if the target is a directory
else
# still need to fix EVENTS since it wants them listed one-by-one
INW_ARGS=("--recursive" "$EVENTS" "-E" "--exclude" "'(\.git/|\.git$)'" "\"$TARGETDIR\"")
fi;
fi
GIT_ADD_ARGS="--all ." # add "." (CWD) recursively to index
GIT_COMMIT_ARGS="" # add -a switch to "commit" call just to be sure
@ -235,8 +245,8 @@ fi
if [ -n "$GIT_DIR" ]; then
if [ ! -d "$GIT_DIR" ]; then
stderr ".git location is not a directory: $GIT_DIR";
exit 4;
stderr ".git location is not a directory: $GIT_DIR"
exit 4
fi
GIT="$GIT --no-pager --work-tree $TARGETDIR --git-dir $GIT_DIR"
@ -249,7 +259,10 @@ if ! grep "%d" > /dev/null <<< "$COMMITMSG"; then # if commitmsg didn't contain
fi
# CD into right dir
cd "$TARGETDIR" || { stderr "Error: Can't change directory to '${TARGETDIR}'." ; exit 5; }
cd "$TARGETDIR" || {
stderr "Error: Can't change directory to '${TARGETDIR}'."
exit 5
}
if [ -n "$REMOTE" ]; then # are we pushing to a remote?
if [ -z "$BRANCH" ]; then # Do we have a branch set to push to ?
@ -341,7 +354,10 @@ eval "$INW" "${INW_ARGS[@]}" | while read -r line; do
fi
# CD into right dir
cd "$TARGETDIR" || { stderr "Error: Can't change directory to '${TARGETDIR}'." ; exit 6; }
cd "$TARGETDIR" || {
stderr "Error: Can't change directory to '${TARGETDIR}'."
exit 6
}
STATUS=$($GIT status -s)
if [ -n "$STATUS" ]; then # only commit if status shows tracked changes.
# We want GIT_ADD_ARGS and GIT_COMMIT_ARGS to be word splitted
@ -351,8 +367,8 @@ eval "$INW" "${INW_ARGS[@]}" | while read -r line; do
$GIT commit $GIT_COMMIT_ARGS -m"$FORMATTED_COMMITMSG" # construct commit message and commit
if [ -n "$PUSH_CMD" ]; then
echo "Push command is $PUSH_CMD";
eval "$PUSH_CMD";
echo "Push command is $PUSH_CMD"
eval "$PUSH_CMD"
fi
fi
) & # and send into background

Loading…
Cancel
Save