Skip to content

Instantly share code, notes, and snippets.

@aconz2
Last active November 3, 2022 13:12
Show Gist options
  • Save aconz2/f78ab70c5ede0043faecbba86b14f2dc to your computer and use it in GitHub Desktop.
Save aconz2/f78ab70c5ede0043faecbba86b14f2dc to your computer and use it in GitHub Desktop.
simple way to get live reloading browser. Pipe list of filenames that will trigger a refresh (see entr)
#!/usr/bin/env bash
trap 'kill $(jobs -pr) 2>/dev/null' SIGINT SIGTERM EXIT
browser=chromium-browser
python3 -m http.server &
$browser "http://localhost:8000/$1" 2>/dev/null &
browserpid=$!
cmd=$(cat <<EOF
active=\$(xdotool getactivewindow);
for x in \$(xdotool search --onlyvisible --pid $browserpid); do
xdotool windowactivate --sync \$x key F5;
done;
xdotool windowactivate \$active
EOF
)
entr bash -c "$cmd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment