Skip to content

Commit 6ea8e8f

Browse files
committed
Support watchexec as an alternative to fswatch
1 parent 884c60f commit 6ea8e8f

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

commands/build-watch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
. "${BASH_SOURCE%/*}/setup"
55

66
"${BUILD_CMD[@]}" || true
7-
"${WATCH_CMD[@]}" | xargs -n1 -I{} "${BUILD_CMD[@]}"
7+
watch "${BUILD_CMD[*]}"

commands/setup

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,24 @@ fi
146146

147147
# Watch ------------------------------------------------------------------------
148148

149-
export WATCH_CMD=(watch --one-per-batch --recursive)
149+
watch() {
150+
local COMMAND="$1"
150151

151-
if [[ "$OSTYPE" =~ ^(linux-gnu|msys|cygwin)$ ]]; then
152-
# The default monitor notifies on read accesses...
153-
WATCH_CMD+=(--monitor poll_monitor '--latency=5')
154-
fi
152+
if command -v fswatch > /dev/null; then
153+
local WATCH_CMD=(fswatch --one-per-batch --recursive)
155154

156-
WATCH_CMD+=(../*)
155+
if [[ "$OSTYPE" =~ ^(linux-gnu|msys|cygwin)$ ]]; then
156+
# The default monitor notifies on read accesses...
157+
WATCH_CMD+=(--monitor poll_monitor '--latency=5')
158+
fi
157159

158-
watch() {
159-
if ! command -v fswatch > /dev/null; then
160-
>&2 echo "WARNING: Could not find fswatch ( http://emcrisostomo.github.io/fswatch/ )."
160+
WATCH_CMD+=(../*)
161+
162+
"${WATCH_CMD[@]}" | xargs -n1 -I{} sh -c "$COMMAND"
163+
elif command -v watchexec > /dev/null; then
164+
watchexec --watch .. --postpone -- "sh -c '$COMMAND'"
165+
else
166+
>&2 echo "WARNING: Could not find fswatch ( http://emcrisostomo.github.io/fswatch/ ) or watchexec ( https://github.com/watchexec/watchexec )."
167+
exit 1
161168
fi
162-
fswatch "$@"
163169
}

commands/test-watch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
"${BUILD_CMD[@]}" || true
77
"${TEST_CMD[@]}" || true
8-
"${WATCH_CMD[@]}" | xargs -n1 -I{} sh -c "${BUILD_CMD[*]} && ${TEST_CMD[*]}"
8+
watch "${BUILD_CMD[*]} && ${TEST_CMD[*]}"

0 commit comments

Comments
 (0)