Skip to content

Instantly share code, notes, and snippets.

@mapio
Created April 17, 2015 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapio/7061f2b4bb344695a9ea to your computer and use it in GitHub Desktop.
Save mapio/7061f2b4bb344695a9ea to your computer and use it in GitHub Desktop.
A small script to serve a local directory via HTTP
#!/bin/bash
# see http://veithen.github.io/2014/11/16/sigterm-propagation.html
trap 'kill -TERM $PID' TERM INT
python -m SimpleHTTPServer & PID=$!
python -m webbrowser -t "http://127.0.0.1:8000/"
wait $PID
trap - TERM INT
wait $PID
exit $?
@mapio
Copy link
Author

mapio commented Apr 17, 2015

Just go to the directory you want to serve and type serve.sh (if you have it in your path, or ./serve.sh if you have saved it in the directory are into). It will start the Python SimpleHTTPServer from the current directory and open the system web browser pointing it to the just started server; once done, hit ctrl-c and it will stop the running server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment