Skip to content

Instantly share code, notes, and snippets.

@searls
Created June 15, 2019 21:34
Show Gist options
  • Save searls/79c5ea8e8a0896fc22d2597a11c3a722 to your computer and use it in GitHub Desktop.
Save searls/79c5ea8e8a0896fc22d2597a11c3a722 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