Skip to content

Instantly share code, notes, and snippets.

@nummi
Forked from searls/preview.sh
Created June 24, 2019 16:31
Show Gist options
  • Save nummi/1b676c5f43149347b75e2581dd81014c to your computer and use it in GitHub Desktop.
Save nummi/1b676c5f43149347b75e2581dd81014c to your computer and use it in GitHub Desktop.
A script I wrote to preview a build directory (in my case Hugo's `public` folder, but adjust to taste).
#!/bin/sh
port=${1-1919}
# 1. Navigate to the built folder & start a server in it
cd public
python -m SimpleHTTPServer "$port" &
server_pid=$!
# 2. Trap any killing of this process so that we kill the backgrounded server
function kill_server {
kill $server_pid
}
trap kill_server EXIT
# 3. Wait a tiny bit for the server to boot, then open a browser window
sleep 0.1
open "http://localhost:$port"
wait $server_pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment