Skip to content

Instantly share code, notes, and snippets.

@theniceboy
Created October 2, 2025 00:37
Show Gist options
  • Save theniceboy/185c2a255ae6c0827404dd0bc3a2d351 to your computer and use it in GitHub Desktop.
Save theniceboy/185c2a255ae6c0827404dd0bc3a2d351 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
# Check for --skip-analyze flag
SKIP_ANALYZE=false
DO_RESTART=false
for arg in "$@"; do
case $arg in
--skip-analyze)
SKIP_ANALYZE=true
shift
;;
--restart)
DO_RESTART=true
shift
;;
*)
;;
esac
done
# Run analyzer and fail with its output if non-zero (only for actual errors)
if [ "$SKIP_ANALYZE" = false ]; then
if ! analyze_output=$(flutter analyze --no-fatal-infos --no-fatal-warnings 2>&1); then
echo "$analyze_output"
exit 1
fi
fi
# From here on, suppress all output
exec >/dev/null 2>&1
# Hot Reload Script
# Finds Flutter pane and sends 'r' key for hot reload
# Function to find Flutter pane
find_flutter_pane() {
# Get all sessions
sessions=$(tmux list-sessions -F "#{session_name}" 2>/dev/null)
if [ -z "$sessions" ]; then
exit 1
fi
# Check each session
for session in $sessions; do
# Get all panes in all windows of this session
pane_info=$(tmux list-panes -s -t "$session" -F "#{pane_id}:#{pane_current_command}" 2>/dev/null)
while IFS=':' read -r pane_id pane_command; do
if [ -z "$pane_id" ]; then continue; fi
# Check if this pane is running flutter/dart related commands
if echo "$pane_command" | grep -i -q "flutter\|dart"; then
echo "$pane_id"
return 0
fi
# Also check pane content for flutter-related text
pane_content=$(tmux capture-pane -t "$session:$pane_id" -p 2>/dev/null)
# Look for Flutter indicators in the content
if echo "$pane_content" | grep -i -q "flutter run\|hot reload\|hot restart\|flutter.*connected\|press.*for hot reload\|press r to hot reload"; then
echo "$pane_id"
return 0
fi
done <<< "$pane_info"
done
exit 1
}
# Find the Flutter pane
flutter_pane=$(find_flutter_pane)
if [ -z "$flutter_pane" ]; then
exit 1
fi
# Send hot reload or restart command
if [ "$DO_RESTART" = true ]; then
tmux send-keys -t "$flutter_pane" "R"
else
tmux send-keys -t "$flutter_pane" "r"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment