Skip to content

Instantly share code, notes, and snippets.

@oddboehs
Created June 4, 2025 22:13
Show Gist options
  • Save oddboehs/dcba91bc7e1a18fccf2539f7c6afc73b to your computer and use it in GitHub Desktop.
Save oddboehs/dcba91bc7e1a18fccf2539f7c6afc73b to your computer and use it in GitHub Desktop.
Watch and pull script that monitors git repository for changes and opens localhost:3000 when updates are detected
#!/bin/bash
# Function to open localhost:3000
open_localhost() {
echo "Changes detected! Opening localhost:3000..."
if command -v open >/dev/null 2>&1; then
open http://localhost:3000
elif command -v xdg-open >/dev/null 2>&1; then
xdg-open http://localhost:3000
else
echo "Cannot open browser automatically. Please visit http://localhost:3000"
fi
}
# Get initial commit hash
last_commit=$(git rev-parse HEAD)
echo "Starting git pull --rebase watcher (every 15 seconds)..."
echo "Initial commit: $last_commit"
while true; do
echo "Checking for updates..."
# Perform git pull --rebase
git pull --rebase
# Get current commit hash
current_commit=$(git rev-parse HEAD)
# Check if commit changed
if [ "$current_commit" != "$last_commit" ]; then
echo "Repository updated from $last_commit to $current_commit"
open_localhost
last_commit=$current_commit
else
echo "No changes detected"
fi
# Wait 15 seconds
sleep 15
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment