Skip to content

Instantly share code, notes, and snippets.

@jupblb
Created October 6, 2023 08:28
Show Gist options
  • Save jupblb/afc7ab9fc491e2ba85e5a7266f407047 to your computer and use it in GitHub Desktop.
Save jupblb/afc7ab9fc491e2ba85e5a7266f407047 to your computer and use it in GitHub Desktop.
Run flutter in terminal with auto refresh (recursive)
#!/usr/bin/env bash
set -euo pipefail
# adb reverse tcp:4000 tcp:4000 || true
PID_FILE="/tmp/flutter.pid"
rm -f "$PID_FILE"
# https://stackoverflow.com/a/2173421
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
(
sleep 10
while [ ! -f "$PID_FILE" ]; do
sleep 5
done
echo "Starting watch"
while true; do
fswatch -ro ./lib --latency 1 --event Updated --event Created --event Removed | \
xargs -n1 -I{} kill -USR1 "$(cat "$PID_FILE")"
done
) &
flutter run --pid-file "$PID_FILE" <&0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment